Reputation: 3791
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 . . .
. . . 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 . . .
Upvotes: 1
Views: 5708
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
Now you can click on it, and it will show the whole route beneath the console
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
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
[ Button1 and Button2 have Test.cs referenced in the OnClick.
Upvotes: 5