2
\$\begingroup\$

One aspect of the game I'm making is each level is made up of room objects, which contain the sprites, physics objects and so on. When you enter a level the whole level is deserialsed and loaded into memory but only the room you are currently in is considered, nothing else is drawn, updated or whatever.

I was wondering how I would achieve this in Unity3d. I can imagine having a hierachry with lots of rooms with the various room contents as children, can I tell unity to ignore everything (for updating, drawing, physics and so on) in the hierarchy but the current room and its children?

\$\endgroup\$
  • \$\begingroup\$ Hey Byte why could I not post a link to what I had already made? \$\endgroup\$ – Guye Incognito Oct 13 '13 at 16:06
  • \$\begingroup\$ Not sure, looked like your link was malformed. Though it's not required to answer the question anyway, so no need to post it. \$\endgroup\$ – MichaelHouse Oct 13 '13 at 16:07
  • \$\begingroup\$ Yeah I malformed it by adding space as stack would not let me post link hosted at neocities.org u know why that is? \$\endgroup\$ – Guye Incognito Oct 13 '13 at 16:12
  • \$\begingroup\$ As I said, I'm not sure why. I wasn't talking about the space you added, you had two sets of 'http'. \$\endgroup\$ – MichaelHouse Oct 13 '13 at 16:32
5
\$\begingroup\$

Several ways:

  1. Groups the objects on a per-room basis. Each room has a root GameObject that you should enable only when you enter in it (or are next to it), and disable the room you were coming from. Maybe it's easier method, but you will load in memory all the room even if only the active one is rendered (if you haven't too much rooms it should be acceptable).
  2. Use occlusion culling to limit the rendering to non-occludee objects. You still have all objects load into memory, but unity takes care to decide what to render and what not, based on its visibility.
  3. Use a different scene for each room, and load(load additive)/unload scene(rooms) when you no longer need them. This generally should reduce the memory footprint, but can create a bit of garbage to be collected, so it may be a little more tricky do handle properly.
| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.