GetAssetPath

I’ve seen 2 more topics similar to this but no one is responding. So I’m gonna try my luck… :smile:

GetAssetPath… blank string? i have this:

    [MenuItem ("MyMenu/Find Asset")]
    static void FindAsset()
    {
    	GameObject myRoot = GameObject.Find("root");
    	Debug.Log("myRoot isNull?" + (myRoot == null) + " assetpath= " + EditorUtility.GetAssetPath(myRoot));
    }

root is from a prefab which contains a model of a cube (not animated, 8 verts, 1 no-alpha material).

Am i doing something wrong there or did they actually put something that does not work?? thanks guys.

Doesn’t work for me either. File a bug report.

The bug report should be on the docs :slight_smile:

Here’s what’s going on:

A prefab is a bunch of gameobjects + components that live in your assets folder. If you would ask one of those for their asset path, it would work.

When you drag the prefab into the hierarchy, you get a different bunch of gameobjects + components, that do not live in the assetsfolder, but they live in your scene instead. The thing that makes this a prefab instance is that the editor still remembers where these gameobjects “came from”.

If you ask one of these gameobjects for its assetpath, it won’t work.

What you can do, is ask the editor for the gameobject in the prefab, that the gameobject you’re interested in “came from”. You can then ask for the assetpath on that gameobject.

Please note that prefabs are completely an Editor only concept.

Take a look at EditorUtility.FindPrefabRoot() for a way to get your hands at the gameobject from the actual prefab.

Good luck,

Lucas

FindPrefabRoot()? where is that? but i think i get what your saying.

so basically it won’t work on prefab instances but rather on prefabs themselves. but since you can’t access the root prefab on the editor, then the function is… useless? or is there a way for me to access the root prefab?