Managing Unity headless server instances

Right now, I’m making a room based game and whenever the game ends, I “clean” the room by destroying all instantiated objects, resetting timers, etc.
I’m just wondering if this is a smart way to do this. There could be a lot of things that I’m not (because I don’t know or can’t) reset like Time.time. Would it be better to just close the instance and relaunch a new one?

Load scene 0.

Could you elaborate a little on what you mean?

I think he answered your question, by reloading the scene technically all your objects should be initialized or (re-initialized) when Load Scene [your_scene_number]; is called. Best thing to do is run the game, put some breakpoints just before you reload the scene and check if your objects are cleaned up and basically “new” again.

I was just browsing through the documentation on how the unity methods get executed Unity - Manual: Order of execution for event functions

Sorry if I didn’t make it clear enough but I’m looking for how people are managing their server instance . I’m aware reloading the scene clears all objects but is that what everyone else is doing? Reloading scene “0”?

Basically, the main issue I see with reloading the scene, at least for myself, is that all values not attached to MonoBehaviours are not reset. That includes static values, singletons (DontDestroyOnLoad), ScriptableObjects, and C# objects like Timers.

Personally I am manually resetting those on startup. When you are about to restart. You should probably Destroy ALL gameobjects. THEN reload. That way all DontDestroyOnLoads will be reset. And statics you will have to deal with manually.

Atleast that’s how I do it. Alternativly you could just completley restart the application.
Otherwise check this: How to restart application - Questions & Answers - Unity Discussions

1 Like