- Home /
do Static classes get serialized?
I have a public static class with [System.Serializable]. It has a public static string variable. When I set its value to "foo" through some other editor script it remains until I enter play mode. Serialization is not happening. What to do?
Static variables do not get serialized. You must either have a component in the scene where you save the values, or on a custom .asset in the project folder which you load on runtime.
Depending on the amount and kind of data you're trying to store you might be able to get away with PlayerPrefs/EditorPrefs. Additionally, unless you're talking about within the Editor, you might also have a look at ISerializationCallbackReceiver to serialize the data yourself.
Your answer
Follow this Question
Related Questions
Serialization of Singleton vs Static class in Editor 1 Answer
Unserialized private variable values from static instance persist when exiting play mode 1 Answer
Can a static class have an Update() function which Unity calls automatically? 1 Answer
Inpsector missing variables from a Serializable class? 1 Answer
How to show the instance of a class's variables in the inspector. 0 Answers