Quantcast
Channel: Answers for "How to know where a particular script is being used?"
Viewing all articles
Browse latest Browse all 9

Answer by ThePilgrim

$
0
0
public class FindPrefabsWithComponent : MonoBehaviour { public GameObject[] prefabs; void Start() { FindPrefabsWithComponentType(); } private void FindPrefabsWithComponentType() where T : Component { print("Searching for components..."); foreach (var prefab in prefabs) { T foundComponent = prefab.GetComponentInChildren(); if (foundComponent != null) { print("Found component in " + foundComponent.name); } } print("search complete"); } } If you want to find all prefabs that the script is attached to, even ones that are not in any of your scenes, you can follow these instructions: 1. Create the FindPrefabsWithComponent c# script above, but replace "Rigidbody" with whatever script you are wanting to find. 2. Create a new game object in your scene and attach the FindPrefabsWithComponent script. 3. Click the small lock icon in the top right of the inspector window to lock the inspector view onto your new game object. 4. In your project, search for all prefabs with "t:Prefab" or by using the filter button immediately to the right of the search box in the project window. 5. Select all of the prefabs in the project window (Ctrl-A on windows) and drag them onto "Prefabs" in the FindPrefabsWithComponent component in the inspector window. 6. Run the game. It will print out the name of the game object that the script is attached to.

Viewing all articles
Browse latest Browse all 9

Latest Images

Trending Articles





Latest Images