Field Values Not Being Saved

  09. Troubleshooting No Comments

The Problem

You have exposed some fields in Power Inspector using an attribute like ShowInInspector or SerializeField. However, whenever you enter play mode or restart unity all the changes you’ve made to these fields are lost.

The Reason

Power Inspector will display any field that contains the aforementioned attributes, but this does not necessarily mean that their values are being serialized. If a field’s value is not being saved into the scene file, any changes you made will be nowhere to be found when the scene is loaded from disk the next time.

The Solution

Instead of using the SerializeField attribute, try using the SerializerReference attribute instead. With this attribute Unity will serialize field values even for abstract and generic types.

In the rare instances where even SerializeReference doesn’t work either (like with dictionaries) you’ll need to handle serialization manually.