- Home /
Get Reliable Instance ID
Hi, I just figured that Instance IDs of MonoBehaviours are created on Scene construction, if you'd call it that way. The issue now is, that I make personalisable Scriptable Objects, which do only have 1 owner and the owner's ID is its InstanceID...
So, when saving and loading the Scene. The InstanceIDs change and aren't reliable. So I have to come up with something else.
Does anyone have something in mind? I'm trying to figure if I can rely on a transform's InstanceID and work with that one. like GetTransfrom(ownerTransformID).GetComponents<ownerComponentType>()[ownerComponentIndex]
That would be more complex than I'd want it to be. Is there an easier solution out there?
Why don't you add an ID field to each owner, and assign it with whatever unique value you want?
I didn't want to write owner classes that derive from $$anonymous$$onobehaviour or ScriptableObject. anyhow, InstanceID's aren't consistent outside the current SceneSession. So I have to do a freaking huge workaround, because the whole process was built on that... ... ... ... alright onto it ;-) thanks for the joining thought buddy ;-)
Even if your owner classes don't derive from $$anonymous$$onobehaviour or ScriptableObject, they can have their own ID field (not InstanceID), which you can make as unique as you like (and persistent), as I already said. Or alternatively, you can get an InstanceID that is unique for a scene, and have the owner assign it to whatever he owns, when the scene loads.