0
\$\begingroup\$

I am using Unity 2018 with Visual Studio Code version 1.43.2 on a Mac.


Things seemed to work fine between Unity and Visual Studio Code, but now I realize that something is wrong with Code. I have been following along with a tutorial and the autocompletion functionality of Code seemed fine until the function OnTriggerEnter, which was shown as autocompleting for the guy in the video (who was using the other Visual Studio), didn't fill in. However, many other Unity things do automatically show up as options.

I looked at this Microsoft help page about VS Code and Unity, and I have everything it I seems I would possibly need to combine the two; I have .NET, Mono, Debugger for Unity, the C# extension, and got Unity Tools for good measure.

Generic C# things like return, void, int, etc. autocomplete, so the C# extension seems fine. Many Unity things, like Vector3, GameObject, Destroy, transform, etc. also autocomplete like they should.

What is wrong here? How can I fix this and get full autocomplete?

\$\endgroup\$
2
\$\begingroup\$

The thing is Vector3, GameObject, Destroy are all staticly typed classes or methods inside classes. Thus intellisense can autocomplete them.

On the other hand, Awake, Start, Update and other 'unity callbacks' are not. What Unity engine does it uses reflection, to check if the MonoBehaviour has any of those 'callbacks' in it (through name (as string) reference). If it does, the callback gets called. Because there's no staticly typed method as Awake, Start, etc., intellisense cannot autocomplete it.

As for solution, there are extensions, can't remember names exatcly, that add snippets for Start, Update and other callbacks.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ What's strange here is that the video OP was watching apparently showed this MonoBehaviour message method autocompleting, though I've never observed that in my own use of Unity & VS. It's possible the creator of the tutorial had set up a superclass or interface that defined this method, though this comes with pitfalls, or was using some additional extension not listed here. \$\endgroup\$ – DMGregory Apr 9 '20 at 11:33
  • \$\begingroup\$ +1 for useful reference link. It explains pretty much everything. 👍 \$\endgroup\$ – eLTomis Apr 9 '20 at 12:59
  • \$\begingroup\$ Thanks! Based on your suggestion I got Unity Code Snippets which adds autocomplete for this stuff. \$\endgroup\$ – Stormblessed Apr 9 '20 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.