I didn’t know that
is there a type of global variable that gets initialized each time a scene is loaded?
Scenes are a Unity concept, not a C# concept, so there are no C# keywords that relate to them.
Also, self-resetting variables are not a thing. Variables are just boxes where you store stuff, they don’t have instructions associated with them. You either need to have a separate non-global variable for each scene (so it is “reset” in the sense that it’s actually not the same variable at all) or you need to write some code that actually goes out and resets it at whatever time you want it to be reset.
For the former, you can have some Unity game object that you create a copy of in every scene, so that there’s always one in existence but not the same one as last scene. For the latter, you can modify whatever script you are using to change scenes.
so if a monobehavior has a static variable and that mono gets destroyed during scene load, that static variable survives uh
i’ll start using scriptable object in the next project, this shit is a nightmare to untangle
The actual MB object never “has” a static variable. The variable belongs to the class itself, not any instance of the class. This has nothing to do with Unity, it’s a C# concept. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-classes-and-static-class-members
yeah i get it now thanks guys
scriptableobject will help me control stuff more visually
You’re not going to find much respite using scriptable objects, its going to be functionally identical to static variables when used as a value store. Values in scriptable objects are still going to be persistent between scenes, they only revert to original value every time the application is opened, and even then it only reverts for a built game.
If the static variable needs to be reverted, a script with the values its meant to revert to running in awake or start, somewhere in the scenes where the static variables matter, should be enough to solve your issue I imagine.
I don’t really understand what you could have learned about “static variables” that made you think that you wanted one without making that result entirely predictable.
Static variables aren’t associated with any instance, so of course they survive when the instance is destroyed, and you can delete the words “during scene load” from that sentence without affecting the reasoning one bit.