References being lost in Prefab Instances when loading scene

I have a prefab which has a script which has a list of references and starts with just one reference.

When adding an instance of this prefab in to the scene and adding references to this list programmatically in Editor mode the added references do not become a bold font like they usually would when manually dragging and dropping/adding to the list and when I save and reload the scene all the references which were added are then lost, to be specific the list doesn’t show that there are any missing references but the list goes back to having only one element/item on the list just like the prefab instance started off when first dragging it in to the scene before adding anything to the list, like it’s in its default state.

If however I do the same as above but before saving I manually change any random variable for this script in the inspector for the prefab instance it causes the inspector to refresh and the added references to the list become a bold font and then if I save and load the scene the references are kept when I reload the scene.

This seems like a bug in the Editor. I’m hoping this will get patched but in the meantime I’m also hoping for a work around, is there any method I can call to force the prefab instance or any object for that matter to refresh/validate its variables?

Using Unity version 6000.0.34f1

Thanks in advance.

You need to call EditorUtility.SetDirty after setting the references via script.

2 Likes

I found what I was looking for I just had to use EditorUtility.SetDirty() after making the changes via code.
Turns out it may be more of a feature than it was a bug.
Hope this helps somebody else in the future.

Edit: I wasn’t trying to steal the glory for this I just happened to find the answer here How do I make fields in the inspector go bold when prefab value is overridden - #3 by Bunny83 after a few obscure searches and just happened to post this at the exact same time as the other user posted their answer lol. Thanks to drgrandayy for rushing to my aid it was the exact answer I was looking for and if I hadn’t found it by pure chance I would’ve been lost without his help.