How do I find all references to a varaible in a C# class INCLUDING references in .unity files

so I’m in C# editor looking through a class. How do I find all the references to a variable or class in the code base and also in the unity files themselves?

Lots of code that seemingly has no connection to anything when working from code.

Unity has to have a way to find all these but I can’t find it.

To find all references of a variable in Monodevelop…

  • To find all references on the page, just ctrl+f to search for it
  • To find all references in all files, ctrl+shift+f (find all), or right-click the variable/class and click “find references”

To find all references of a class in your scene…

  • Go to your hierarchy search box and search: “t:ClassName” (obviously using your classes name in place of “ClassName”)

Is this what you were looking for?

finding references to variables, functions or classes (objects in general) in mono is trivial and works well.

What I’m having heartburn over is finding all the things in the unity IDE that reference what I’m looking at in mono.

So, if this search t:varaiablename can find all references anywhere in Unity IDE to whatever object in mono (at this point I have no idea where it’s referenced or even if it’s referenced outside of mono), that’s what I’m looking for…

For code related stuff, you can use the IDE “Find references” feature.

I use MonoDevelop (on OSX), i can select a method, field or class, right-click and select “find references” to get a list of references to what is highlighted.

What do you mean by references from the Unity IDE (of variables, functions, classes) ? in the IDE, game objects can only reference your scripts (MonoBehaviour based classes). Is this the kind of reference you’d like to find? if not , i misunderstood the question.

I have built an editor extension that lets you select an object in the Unity editor (e.g: a script file, for example) and then it shows you all the references to it (game objects that use that script, for example).

If this is the thing you’re looking for, i can share that with you.

yes, as you note, the Mono IDE is very good at this sort of thing (and a lot of other sorts of things). I can find anything in C# from inside Mono no problems. The couple of times I’ve had problems finding something I can do word searches for fragments of related text. Good deal. What I expect.

The problem comes in when I have no idea where in Unity IDE land it references some, let’s say, variable in a C# file.

In my example, I have a class in C# that is used somewhere in Unity (unknown to me). It has a variable that is instantiated as FALSE. Never changed in code but it is always has a value of TRUE when it comes through the code. Somewhere in Unity it’s being set in the IDE. I need to find the place and kill that behaviour. How do I do find it?

That sounds like as good as it gets and would at least be able to let me find the gross access points.

you can use this script for finding project references to various assets in your project: Reference Finder - Pastebin.com

These will appear as warnings in the console for now (until i will have the time to make a create a nicer solution such as a new window or something like that).

1 Like

Thank you much!