- Home /
Why do Prefabs lose array data when starting the game in editor?
I'm noticing some odd behavior around prefab-vs-unpacked objects with array properties. I have a MonoBehavior script with an array of a Serializable class as a public property. As expected, this shows up in the inspector, I can add and remove elements, and they persist when saving and quitting Unity, run the game from the editor, etc.
What's odd is that if I put that MonoBehavior script on a prefab, and pull the prefab into the scene, suddenly I lose the contents of the array any time I run the game in the editor, or save and quit. If I unpack that prefab, then setup my array on the unpacked object, it works as expected again.
Is this the intended/expected behavior? Non-array properties on the same script seem to keep their values. Feel like I must be missing something here. I'm guessing it's pulling the empty list from the prefab for some reason, but I'm not sure why it's only doing that for the array.
Answer by timothy-s-dev · Jun 03 at 05:31 PM
Discovered that the issue only happened when the values were being set by an editor script, and from there was able to find the EditorUtility.SetDirty()
method which, when called on every object that gets updated in the script, fixed the issue of the values being lost.
Your answer
Follow this Question
Related Questions
Standard Assets disappears in somes Android Phones 0 Answers
Hiding gameobjects in hierarchy make it less expensive ? 0 Answers
How can i convert a prefab instance to an ordinary game object? 2 Answers
Is it possible to drag/drop/increment into editor array? 1 Answer
Prefabs are instantiated in editor but not in executable 2 Answers