Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

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

Discussion in 'Editor & General Support' started by Randy-Lee, Jul 24, 2015.

  1. Randy-Lee

    Randy-Lee

    Joined:
    Oct 8, 2014
    Posts:
    11
    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.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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?
     
  3. Randy-Lee

    Randy-Lee

    Joined:
    Oct 8, 2014
    Posts:
    11
    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...
     
  4. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    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.
     
  5. Randy-Lee

    Randy-Lee

    Joined:
    Oct 8, 2014
    Posts:
    11
    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?
     
  6. Randy-Lee

    Randy-Lee

    Joined:
    Oct 8, 2014
    Posts:
    11
    That sounds like as good as it gets and would at least be able to let me find the gross access points.
     
  7. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,559
    you can use this script for finding project references to various assets in your project: http://pastebin.com/9bkv1zRT

    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).
     
    Last edited: Aug 18, 2015
    Randy-Lee likes this.
  8. Randy-Lee

    Randy-Lee

    Joined:
    Oct 8, 2014
    Posts:
    11
    Thank you much!