Instances between levels

If I understand correctly, static objects (which we’ve used quite a few of) persist between scenes. What would be the best way to make sure everything is as it should be when loading a new level? My current thought is to create a level transition script to fire an event that resets all subscribers to default values. Though, it feels like that approach is very open to missing something and causing errors.

static references persist through scenes, but not the objects themselves (unless you add DontDestroyOnLoad)
So when you do a scene change all the objects are destroyed and all those references will be pointing to null thus essentially handling clean up automatically.
Remember the only thing that is static is a reference to the instance, not the class/object itself, those have one single instance which exists in the scene and is cleaned up on scene change.

2 Likes

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms