'Visual studio 2022 is not auto-completing certain methods

I have recently downloaded visual studio 2022 for use in Unity and it was working correctly for a while, but today it has stopped auto-completing certain method names such as OnMouseButtonDown() and OnTriggerEnter2D(). Other methods such as Start() and Update() do work, but a majority of Unity specific methods are no longer auto completed. I've tried restarting visual studio code, restarting my computer and uninstalling and reinstalling visual studio code, but the error still persists. Any help would be greatly appreciated. Thanks.

Image of issue



Solution 1:[1]

This problem can cause various of reasons, even some IDE bug (which Visual Studio 2022 has a large number) but there is pretty common solution for this one

Firstly you'll have to make sure, that your Game development with Unity workload is checked

So

  1. Open Visual Studio Installer and click Modify button across your version of Visual Studio.
  2. Click on a Workloads panel and make sure that Game development with Unity workload is checked as shown on the image
  3. Click Modify button at the bottom right corner.

Then you need to ensure, that desired version of Visual Studio is set as a External Script Editor inside Unity engine

  1. Open Unity
  2. Edit -> Preferences -> External Tools

And make sure that External Script Editor set as a current version of like so

Click on Regenerate project files button and try to always open your scripts directly from Unity

Restart Unity after those steps

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1