Trying to get the Path of components on non-instantiated prefabs

I am doing an editor script and I want to list paths of components (for example: Where’s that FBX on the non- instantiated prefab originating from?)

I think I’m close: I can in fact get the path of an instantiated prefabs component, but when I’m looking in non-instantiated prefabs, the path appears to be returning as the Prefab - not a file?

    public static void componentAndPathButtons(GameObject checkthis)
    {
        Component[] allComponents = checkthis.GetComponentsInChildren<Component>();
        foreach (Component singleComp in allComponents)
        {
            string path = AssetDatabase.GetAssetPath(singleComp);// This returns the Prefab as 'Path'. How do I get file path?
            GUILayout.Button(singleComp.name + "." + singleComp.GetType().ToString() + "

" + path);
}
}

Well components are not assets. They might be part of an prefab-asset. Components never have “asset files”. If they have they are part of a prefab (custom generated prefab or “imported/auto generated” prefab). So an instance of a custom prefab only have a link to the prefab it comes from. However other assets usually still reference it’s original source. By that i talk about Meshes, Materials, Textures. Those are assets and have a file they belong to.

You said

the path appears to be returning as
the Prefab - not a file?

But a prefab is a file as a prefab is a standalone asset.

For example an “FBX file” is not a single asset. The FBX file itself usually imports as “model-prefab”. However that prefab only consists of auto generated gameobjects and components to hold the actual “content” of the model. The actual content is for example the Mesh object which usually shows as sub-asset and is referenced by the MeshFilter or SkinnedMeshRenderer component.

When you create a new prefab out of the content of the FBX, it’s a new asset that just has references to the content of the original prefab / asset / sub-asset.

Of course when you have a reference to a component / gameobject of an actual prefab, GetAssetPath will give you the path of that prefab asset.

You may want to check actual asset types instead (i.e. the sharedMesh of a MeshFilter / SkinnedMeskRenderer, the sharedMaterial of a Renderer, …)