How are unity references serialized? (instanceID related)

Hi

I'm building some serializing logic, and I'm trying to serialize a reference to a unityObject. What I have come across is AssetDatabase.GetAssetPath --> AssetPathToGUID. Which works quite well, but not for assets which aren't the "main" asset. And object.GetInstanceID --> EditorUtility.InstanceIDToObject which works even better.

But I wonder how references are serialized in the project by Unity, is it using InstanceIDs?

And is there a risk with using instanceIDs? Are they changed by Unity sometimes?

Lastly, is there a better way to serialize references?

Thanks, Aron

This is not a definitive answer since I'm not an expert, but I don't see anything that changes InstanceIDs, and I see some infrastructure that saves them (I think). So it seems like you can use InstanceIDToObject and GetInstanceID.

check out GitHub - terravision/UnityTextScene: A toolset for working with text-based scene files in Unity (http://www.unity3d.com) instead of the built-in binary format.