GetComponent not valid in given context

Hi all im on the how to trigger sounds lesson and i done exactly as showed in the video yet unity gives me the error CS0119 GetComponent is a methon, which is not valid in the given context, i have provided a screenshot, any help appreciated

I also dont get the auto complete options show up, i installed the extensions recommended at the start of the course even uninstalled and reinstalled but to no success, any help with that also, thanks!

image

i have found what i was missing, after hours lol. But still dont know why im not getting auto complete things show up so still need help on that part :smiley:

Edit: This screenshot is to show what i was missing, this is not related to the autocomplete issue…

I don’t remember ever seeing autocomplete completing the parenthesis when you’re seting the generic. Strike up the editor… Yep, it doesn’t do it, you have to open the parenthesis yourself. You get the autocomplete for GetComponent and AudioSource. At least this is with my Visual Studio Code setup. Maybe programmers are expected to do some of the work.

Hi iHush,

Welcome to our community! :slight_smile:

Do you use Visual Studio or Visual Studio Code?

i mean there is no autocomplete or suggestions AT ALL not just for what i was trying to do…

Hey thanks! I use visual studio code!

Nina has a whole bunch of suggestions for fixing Visual studio Code for autocomplete. Scroll through the Unity section and you’ll stumble upon one of the 50 threads that cover this topic.

My suggestion is usually Ctrl-Shift-P and make sure you’re in the right project (for some reason vs code durps) and then Ctrl-Shift-P again to restart it. Learn it. I seem to stuff it up often as I have to do it once every week or two to get Autocomplete back working.

Please follow the instruction on this website and make sure all required extensions are installed: https://code.visualstudio.com/docs/other/unity

If the issue persists, please check the console of VS Code (not Unity!). If the .NET Framework 4.7.1 (Developer Pack) is mentioned there, download and install it from the official Microsoft. Here is the link: https://dotnet.microsoft.com/download/dotnet-framework/net471

Depending on your version of Unity, it might be that you will have to install the “Visual Studio Code Editor” package in Window > Package Manager in Unity.

Maybe you’ll have to reboot your computer. Then launch Unity again and open one of your scripts.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms