Hi everyone,
for a project where I want to work with Unity’s yaml files, I am trying to link the fileIds from the yaml to the objects on my scene. I tried
GameObject[] gos = SceneManager.GetActiveScene().GetRootGameObjects();
foreach (GameObject go in gos) {
string guid;
long file;
if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(go, out guid, out file)) {
Debug.Log("Asset: " + go.name + " Instance ID: " + go.GetInstanceID() + " GUID: " + guid + " File ID: " + file);
}
}
but for a reason I can’t think of, TryGetGUIDAndLocalFileIdentifier
returns false for all the game objects while the game objects themselves are listed correctly. What did I overlook? I mean, it’s called TRY get GUID etc, but the documentation only says it will return false when it fails, not what could cause it to fail.
Thanks in advance. If you know of a better way to achieve what I need - a data structure where I can find objects in the scene based on the fileId from the scene’s yaml - I’ll take it, too. Ideally, this should work for components, too, I just started with the root game objects because that was easy.
I know of GlobalObjectId.GetGlobalObjectIdSlow()
but all those methods are probably called Slow for a reason. There must be a working reasonable method, I can see all the things I need in the inspector…
I also know of UnityEditor.Unsupported.GetLocalIdentifierInFileForPersistentObject()
but that only works for objects stored on disk (persisted objects) and also I bet it’s in a namespace called Unsupported for a reason.