huynguyen
huynguyen

Reputation: 7760

How to know image is used in which prefab

How to know which image is used in a prefabs? In the project (modified from a project on Ray Wenderlich) below, I have an image named cat.png. I use it in MyPrefab.prefab. Suppose that I'm not the project creator, how can I find out which prefab each image came from?

enter image description here

Upvotes: 2

Views: 228

Answers (2)

Programmer
Programmer

Reputation: 125275

This has been answered before. You can find it easily by using code. Just put the code below in the Start() function and click Play then stop. It will show you the Prefab the GameObject/cat picture belongs to.

   void Start()
   {
        GameObject prefab = GameObject.Find("cat");
        Object GameObject2 = UnityEditor.PrefabUtility.GetPrefabParent(prefab);
        string prefabPath = UnityEditor.AssetDatabase.GetAssetPath(GameObject2);
        Debug.Log("Path: " + prefabPath);
    }

OR without Code:

Select the object/cat from the hierarchy then on the Inspector on the right, click Select and the prefab name will be displayed and selected in the Project tab.

enter image description here

Upvotes: 5

Tom
Tom

Reputation: 2472

If you click on your prefab, and go to the inspector, there should be a Sprite Renderer component. In it, there will a variable called Sprite and then your sprite next to it. If you click it (or double click, I forget which) it should highlight in your project.

Upvotes: 0

Related Questions