UnityEngine.Object field pointing to Project file gets serialized by JSON as instance ID. After deserialization field points to different Object. Why?

I’m writing todo list in EditorWindow. All it’s data is being serialized as separate text JSON files. One of the fields in every entry is of type UnityEngine.Object and they are pointing to Project files for some context (serialized by JSON as instanceID). But problem is: after editor restart and deserialization this field now points to very different Object.

I observed that one particular asset has id of “19658” but reference to it gets serialized as different number, “16670” for example. I suspect instanceID is not good value to use but I’m not sure what is the best way to go about it. Any ideas?

Serialize Object field as asset path instead? (not ideal as easily breakable)

Some another type of GUID?

I’m doing this out of my head and I’m not 100% sure. But I believe InstanceID as you describe does not survive serialization/deserialization (I thought that it for this reason didn’t even survive going in/out of playmode but I’m not sure on that one).

Anyway, I believe you actually provided the answer kinda with your question :stuck_out_tongue:

Use the guid, which you can find from the assetpath