- Home /
Question by
Semetre · Oct 12, 2018 at 01:31 PM ·
c#scripting problemprefabstatic variable
If I declare and initialize a public static variable in a prefab, will that variable retain its value or reset every time the prefab is instantiated?
In my case, I have:
public static bool prevReversed = false;
The above is written in a script that's attached to a prefab as one of its components.
Is prevReversed
going to become false every time the prefab is instantiated, or will it retain its value?
Comment
Answer by SkaredCreations · Oct 12, 2018 at 02:28 PM
Static variables retain their values for the lifetime of AppDomain, so they're not re-initialized upon newly prefab instantiated.
It's basically the application lifetime, class static variables are valid until the application is closed (AppDomain is the environment where the application is executed in .NET).