- Home /
Get prefab's path in file system
Hi all. I have game object on my scene, it's prefab. I want to find it on assets. I tried to find it, using AssetDatabase.GetAssetPath, but it returns nulls. Here's the code:
[MenuItem("Custom/Check item")]
private static void CheckSelection()
{
if (Selection.activeGameObject == null) {
Debug.LogError("No item selected");
return;
}
var go = PrefabUtility.FindPrefabRoot(Selection.activeGameObject);
Debug.Log(AssetDatabase.GetAssetPath(go) + " " + AssetDatabase.Contains(go));
}
What's the right way to find prefab in file system?
Answer by Rustam-Ganeyev · Mar 06, 2013 at 11:08 AM
Ops, i found answer. I needed to use PrefabUtility.GetPrefabParent instead of FindPrefabRoot:
var go = PrefabUtility.GetPrefabParent(Selection.activeGameObject);
Debug.Log(AssetDatabase.GetAssetPath(go) + " " + AssetDatabase.Contains(go));
Answer by Sky-Foxy · Nov 02, 2016 at 03:46 PM
If you need find object in Prefabs, Material, Scene, by GUID https://gist.github.com/AndreySkyFoxSidorov/977e5b0a91b3bc3e2acf53917e32f410
Click Right-click select "Find GUID in Prefabs Material Scene" the object to find in Prefabs, Material, Scene, by GUID.
Your answer
Follow this Question
Related Questions
I need to hack my PC built game .assets files - but how? 1 Answer
Getting Prefab Icon from AssetDatabase 0 Answers
AssetDatabase.AddToObject with existing assets 1 Answer
Refresh single asset 1 Answer