- Home /
Unity. Some fields go to null on Play
I Mean those fields.
[SerializeField]
public Type gameStateType;
[SerializeField]
public IGameStateParams gameStateParams;
I made in Editor methods to set those fields up, but, when click Play they go null.
I can deal with Type(all supported by my system types stored in dictionary, so i can just use their ID to get Type), but not with IWhatever implemented instance.
Can it be solved?
If not, is there any way to store in scene game object any IWhatever implemented instance?
Answer by tyruji · Jul 22, 2021 at 12:21 PM
In short, Unity doesn't serialise interfaces nor Type objects. You have to design your system differently. Also you might want to take a look at abstract classes for replacing interfaces, since these do in fact serialise.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
C# how to setup a Binary Serialization 4 Answers
How do you use serialized values at creation? 1 Answer
Saving serialized data for iOS 0 Answers