Maintaining Object references between Edit and Play mode

I'm writing an Editor Window that lets me configure some `ScriptableObject` objects. One of them contains a reference to a `GameObject`. If I set that reference through the GUI during edit mode, then when I switch to Play mode the reference has become `Null`. When I then switch back into Edit mode the reference has come back again (in other words, I presume that the set of `GameObjects` during play mode are not actually the same objects as you see during Edit mode).

Any ideas how to make my objects automatically point to the current references during Play mode if they've been set up in Edit mode?

Old question but something I’ve dealt with recently. Sounds like you are running into a non serialized property.

This can be either a Static or Private property that on play is ‘initialized’ to it’s default value and therefore losing the preplay value.

So one way to fix would be to set the property to [SerializableField, HideInInspector] or make it public.

If it’s a static property you’ll need to assign it to a local instance property (i.e. every time it’s changed) and then serialize that property as mentioned above.

On play however you’ll then need to reassign that property back to the static representation.

I had similar probleb. Solution it is about using PrefabUtility.RecordPrefabInstancePropertyModifications().
Here is a ref,I had this problem. Solution it is about using PrefabUtility.RecordPrefabInstancePropertyModifications(). This allow you to save references bitween objects. Here is a ref Unity - Scripting API: Undo.RecordObject