remudada
remudada

Reputation: 3791

How to find Script usage in Unity UI Design

I have been asked to maintain a Unity project that has been built and maintained by different developers. I have discovered source CSharp files that I am almost sure are not being used. How can I safely remove such unused files from the Unity Project? I fear that there may be usages somewhere in the UI design like . . .

enter image description here

. . . and I'll end up with broken references that are even harder to discover and fix.

EDIT: Using 'find references in scene', lists a whole bunch of references but I cannot find any link to the file in question. Here's an example . . .

enter image description here

Upvotes: 1

Views: 5708

Answers (2)

Richard
Richard

Reputation: 1038

With the "Find references in scene" method (accepted answer) You will only get what it's called or beign instanciated by the scene elements only. Which means that every scripts that are called or invoqued by another script from/by your unity project and parameters will not appears.

So the best way is to trace it by putting a Debug.Log(); in the said script, within his awake method

private void Awake()
{
    Debug.Log("here");
}

Then you play your scene and look at the console. If the script is used ANYWHERE, you'll see something like this

enter image description here

Now you can click on it, and it will show the whole route beneath the console

enter image description here

In my case, I can tell it is instanciated within the XRBaseController.cs script. And I even can double click on it to open it and see what it's like

Upvotes: 1

Remy
Remy

Reputation: 5163

You can right click a script in your project window > Find references in scene.

This will filter your Hierarchy to just GameObjects that have a reference to that script (Either directly attached as component, or through onClicks etc.)

Alternatively you can apply this filter yourself in the search of the Hierarchy like using: ref:PathFromAssets/ScriptName.cs. example: ref:Scripts/Player/PlayerMovement.cs.cs

[Find References in scene[2] Found references Button1 and Button2 have Test.cs referenced in the OnClick.

Upvotes: 5

Related Questions