- Home /
How to identify an asset?
Hello. I have a following problem: 1) There can be many asset objects contained in the same file, so LoadAllAssetsAtPath returns multiple objects for one file. 2) After restarting Unity those objects seem to get new Instance IDs, so those are not persistent. 3) There can be multiple objects with the same type/name within a file. So the question is: how do I conclusively identify asset object as the same one I've worked with in previous Unity session?
Answer by Lucas Meijer 1 · Jan 18, 2010 at 09:29 AM
Could you describe on a bit higher level what you're trying to achieve? Internally the different objects in an assetfile have a identifier number, however we don't expose that currently (as that gives us the freedom to change how we identify them, which we actually do from time to time). You can use a combination of UnityEngine.Object.name and the result of GetType(). The only type of asset that I can imagine where you'd run into this problem would be imported 3d models / prefabs. In those cases, you could write an AssetPostProcessor, that does something to the objects before they're written to disk that would make them more easily identifyable. Changing the name would be a likely candidate. If we're talking about gameobjects, you could at this point also add a custom monobehaviour that could carry an identifying string. Again, it's a bit difficult to give solid advice without knowing what you're trying to actually do.
Answer by Ashkan_gc · Jan 18, 2010 at 02:03 PM
i think the best way is to create an special component that holds unique information about each gameobject. you can generate your own IDs and version and ...