I am using Unity 2D for the past 2 weeks and when it came for changing rooms i got disappointed. Its not like ex. Gamemaker where you press a button and the room becomes persistent. I have though a way of making the scenes persistent and thats:

*Save all the variables that make the scene as it is(positions, etc.)

*Change scene.

*Move back to the same scene.

*Apply the saved data.

So, will this work? If it doesnt work or if its not good, what is the easiest way of doing that?

Thanks in advance


1 Answer 1


you can use DontDestroyOnLoad on any gameObject to make it persistent between scene changes. Then simply have some logic that either enables or disables the object based on the level name. Another approach is to have everything in the same scene but on different layers and switch between cameras to render the desired object. Your way is also viable but its a pain in the ass to implement.

Edit: Like it was suggested in the comments instead of using the different layers approach all the room objects could be parented to a single empty gameObject and then you can enable disable that object. This might very well be the simplest thing to do.

  • \$\begingroup\$ Instead of using different layers you could also put each room into an own game object and then set them active/inactive. \$\endgroup\$
    – Philipp
    Jul 5, 2016 at 8:41
  • \$\begingroup\$ So, I will simply add DontDestroyOnLoad on every gameobject. So, after changing room these objects will be transfered with me and then I will disable all the unneeded gameobjects and re-enable them right after returning to room! \$\endgroup\$ Jul 5, 2016 at 8:44
  • \$\begingroup\$ @PanagiotisIatrou well yes that is one way of doing it. \$\endgroup\$
    – Uri Popov
    Jul 5, 2016 at 8:46
  • \$\begingroup\$ Ok, thanks for helping me on this painful problem(not painful now :D) \$\endgroup\$ Jul 5, 2016 at 8:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .