Is it possible to get the filepath of the source FBX from a game object?

I would like to be able to return the filepath of an imported FBX by passing a game object that uses it to a script (from the Editor, not runtime). For example If I have myHero in a scene I want to select myhero in the scene view, run the script and return C:\UnityProject\Assets\myhero.fbx



If you instantiate the myHero object by dragging the FBX into the scene, you can use AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(gameObject)).

If you instantiate it some other way (for example, the FBX is part of some other prefab), a hacky way is to use AssetDatabase.GetAssetPath on any of the children of the FBX asset that you have access to (for example, a Mesh or an Avatar). That will return the path of the FBX asset itself.

These paths start at your project’s Assets directory.