OnTriggerEnter2D Not Auto Completing or Highlighting Blue

7_br_cud
block-breaker

#1

Hello,

I’ve been following the class so far without issues, however for whatever reason when typing OnTriggerEnter2D it doesn’t pop up the autocomplete options. If I continue the command manually it never highlights it blue.

Am I missing something? I do want to point out that all the code is working as expected. The ball dropping off the screen causes the game to proceed to the “Game Over” scene.

image

image


#2

I see the same. Hoping someone will know the answer as I can’t seem to find the answer on the web.


#3

If you look on the right-hand side (default location) for the Solution Explorer, is the solution and project loaded? If you only had the file open and not the project Visual Studio wouldn’t have loaded all of the .dlls/libraries required to support Intellisense. That said, the MonoBehaviour inherit might underline also at that point.

Some other things to try/consider;

  • save the script / close / re-open Visual Studio
  • check that Visual Studio is up to date, yellow notification flags appear at the top if there are updates to install

Versions of both Unity and Visual Studio could be useful here also.


#4

I am using VS 15.9.5 and Unity 2018.3.0f2. It looks like the project/solution is open in the Solution Explorer.

Intellisense has been working fine for everything except OnTriggerEnter2D and OnCollisionEnter2D. And as the OP mentioned the code is working fine.


#5

That’s really quite strange.

Could you zip your project files up and share them with me so I can test this end?

The forum will allow uploads of up to 10MB, if your project files (zipped) are larger than that you would need to use a service such as Google Drive or Dropbox, and then share the URL.


#6

You can acess the project via https://drive.google.com/open?id=1bZgxG65cFvmtG4QxpI_JRgJC4YTFJT4Y


#7

Hi Andrew,

I’ve opened your project and it looks fine for me;

image

That would suggest its related to your setup at your end, which in one sense is a good thing, as you can be assured your code is ok.

One thing you could try is cleaning the solution, this should clear any caching of the solution/projects held locally.

  • close any open scripts within Visual Studio
  • right-click on the solution within Solution Explorer
  • click on Clean Solution
  • after a few seconds you should see a message similar to this in the output window (defaults to the bottom of the screen)
    image
  • re-open LoseCollider.cs and see if the OnTriggerEnter2D method is now correctly highlighted
  • if not
    • close Visual Studio
    • close Unity
    • re-open Unity
    • double-click the LoseCollider.cs script within Assets to open it within Visual Studio
    • see if the syntax is now highlighted

Let me know how you get on :slight_smile:


#8

Tried all of your suggestions but still not highlighting/autocomplete correctly.

Tried uninstalling VS and reinstalling via Unity Hub - same problem.

I will continue looking on the web to see if I can find an answer. Just strange.


#9

Just out of interest Andrew, what if you create a new project, literally empty, but then create a new script and add the OnTriggerEnter2D method, does it do the same?


#10

I created a new project and had the same behavior. Actually this time the Collider2D type in the method parameters didn’t show up either.

Not sure if it is related but other “Standard” method names don’t autocomplete or highlight as well - such as Start and Update.


#11

Hey Andrew,

If you expand the References in the Solution Explorer on the right-hand-side of Visual Studio, if you scroll through, do you see several that mention Unity in that list?

image

Assuming you have Intellisense enabled within Visual Studio;

…the only reason I can think of as to why this would be happening would be because Visual Studio isn’t able to reference the required libraries. If they are shown within the References under Solution Explorer.

As mentioned before, there was a recent version of Visual Studio and the Visual Studio 2017 Tools for Unity which had an issue and were not correctly re-loading projects, this would mean that a script was opened on it’s own effectively, without the reference to the project and thus, without the reference to the Unity libraries under Resources - this would cause the behaviour you are describing.

Assuming you have no updates due to install for Visual Studio, Intellisense is enabled and those library references are displayed I cannot think of any other reason why this wouldn’t be working for you.

The only thing I could suggest really at this point would be to uninstall Unity and Visual Studio (thoroughly), the reinstall Unity, ensure Visual Studio 2017 Community Edition is enabled as a component to install and see if after a re-install things are any better.


automatically bumped #12

automatically bumped #13

#14

Hi @Andrew_Drake, did you get to the bottom of this?


#15

I looked at the ideas in your last post and ever thing looks like it should and still the same problem. Reinstall did not change it. It doesn’t recognize/autocomplete any methods names - not even Start and Update - although it does recognize all other parts of the first line in the method such as private, public, void and types used to define the arguments like int or Collider2D.


#16

Hi Andrew,

Do you have access to another computer that you could install both Unity and Visual Studio upon and then open the project on that? It would be beneficial to try to isolate the issue.


automatically bumped #17

automatically bumped #18