T O P I C R E V I E W |
Jorge24 |
Posted - Aug 11 2020 : 7:00:38 PM I'm programming in C# in Unity (the game engine). When trying to find the places where the bool "AllowGalaxyMenyPopUp" is referenced I get an error that says "Find References is not available because the symbol unrecognized"
I think this happens only when the trying to find reference to it after using "GetComponent<>()"

|
7 L A T E S T R E P L I E S (Newest First) |
Jorge24 |
Posted - Aug 17 2020 : 11:22:08 AM I see, thats interesting. Yeah, learning never stops lol Thanks again for opening a case! |
feline |
Posted - Aug 17 2020 : 05:38:42 AM Thank you for explaining. When I started trying to understand the problem I wasn't sure if this was a Unity specific problem, or a feature of the C# language its self that VA did not properly handle. It turns out to be a C# language feature, nothing to do with Unity its self, but it took a bit of reading to figure that out. Always something new to learn 
Certainly valid and reasonable C# code, even if not always as clear as it could be, and VA should handle this correctly, hence the bug report. Thank you for the bug report. |
Jorge24 |
Posted - Aug 15 2020 : 2:32:05 PM I see, thank you for looking into it and making a bug report. We dont always create a variable to store the value of GetComponent<>() and then use that reference to call a function or get a property of that component. This is less performant because you then have to retrieve a reference to an object from heap and also it takes up more lines of code for not much benefit.
Maybe that was not exactly the reason in this case (I didnt write the code that I screenshotted to be honest) but there are valid reasons to do it that way like I described above. In this case what happened probably was that the first person who worked on this class maybe created a variable that references the component but other people who worked on it later didn't realize a reference already existed so they just did GetComponent again. This kind of things tend to happen when multiple people work on the same file over long periods of time and sometimes they are just trying to get a hotfix done to get rid of a bug or something and there are no strict code reviews. Happens in indie projects or small game studios like the one I'm working at.
The reason why you would create reference to the component first and then access methods/properties through that reference is usually for readability, esp if its used in multiple places. But if you're just trying to use it in a single place in your cs file, then you would just use GetComponent<SomeClass>().MyBool |
feline |
Posted - Aug 15 2020 : 10:14:55 AM VA is not working out the correct type when the generic function is returning a generic type, I have put in a bug report for this:
case=142800
interestingly in the very simple example shown here:
https://docs.unity3d.com/ScriptReference/Component.GetComponent.html
in the unity documentation, the type of the return from GetComponent is set clearly with a new variable before being used, which would obviously help VA to follow what is going on, but is also not how your code is written. |
feline |
Posted - Aug 14 2020 : 1:22:08 PM I am seeing the same problem here, I am looking into what is going on with these generic functions in C#. |
Jorge24 |
Posted - Aug 13 2020 : 1:18:03 PM the reason galaxy looks different in the screenshot is just that I had also made a Ctrl+F search for "Galaxy", however, if I go to the bool's declaration at the top of the class, and then do VA's find references, it doesn't find the instances where the bool is accessed through Unity's GetComponent<>() .
Here are Visual Assist's "Find References"(Alt + Shift + F) results:

And here is Visual Studio's "Find All References" results (Shift + F12):

As you can see, Visual Studio found 4 more references than Visual Assist.
|
accord |
Posted - Aug 13 2020 : 08:05:01 AM Did you select part of the symbol name? The background color of "Galaxy" is different. When you use the Find feature of Visual Studio, or you just press F3 to continue searching, Visual Studio selects the text you are searching for. In this case, Visual Assist throws this same error message that you show on the screenshot if VA Find References is triggered. If you dismiss the selection first (e.g. via pressing ESC), then it should work after. |