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?
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.
answered May 12 '11 at 05:30 PM