Serialization issue ?

The issue in one image :

9451487--1327007--upload_2023-11-5_18-4-47.png

I have a ScriptableObject instance that holds data.
This ScriptableObject have a field of type BuildTarget.
I access the value of this field in an EditorWindow and display it as a text with the ToString() method. It gives me another value than the one expected.

I never modify this field by code.
9451487--1327010--upload_2023-11-5_18-10-47.png

I don't know why, I have no clue why !?

Because you are using two different instances of the SO. Log their GetInstanceID() values and you'll see they are different. Why, that's up to you.

But one tip: in an editor script, you either have to load the SO asset via AssetDatabase, or use SerializedProperty to read and write the fields of the editor's target property - the 'target' itself is a temporary instance the editor uses, it will only contain default values.

Hello, thanks for your answer, but I already load SO by using AssetDatabase API.

9465110--1329890--upload_2023-11-11_16-37-37.png

The problem remains.


Do you also call AssetDatabase.SaveAssetIfDirty(..) with the object passed in?

And if so, did you run EditorUtility.SetDirty(..) on the SO instance? Because changing fields of an SO by script does not mark it as dirty.

I don't update the file from the EditorWindow, only from the standard inspector of the SO !