Disable errors for a script

So there is a bug in visual studio where it doesn’t recognize unity ui and I have already done some research on this problem and it is a bug. Basically, I am getting errors for all my scripts containing UI and it is flooding my visual studio Error List so I can’t see the important ones. Is there a way I can disable the error warnings for that script?

c# - Unity Scripts edited in Visual studio don't provide autocomplete - Stack Overflow).&text=Check%20if%20it%20works%2C%20if,and%20now%20it%20should%20work.

Pretty sure there is a proper solution for this. Did you set the correct editor and .net versions?
Editor: Edit → Preferences → External Tools → External Script Editor. Change that to (your installed version of) VS.
.Net: Edit → Project Settings → Player Settings → Other Settings → Check API Compatibility Level → Set .Net Version.

Just ignoring a problem is hardly a solution. There is a reason this is happening and i’m pretty sure if it’s not the above, then somebody else with more experience in Unity will know the solution.

Edit: Guess StarManta was faster, but i hope this solves it.

What is .Net and how do I go to its Edit tab

Is the Unity UI package installed in your project?

yes, only visual studio is giving the error not unity

Maybe the way i presented it was a bit unclear but it’s both Unitys’ menu edit. I just marked where to find what.

@Yoreki okay it says i am using .NET standard 2.0 the only other option that i can change it to is .NET 4.x

So… have you tried that? And set your editor to VS? Are the problems gone? Some actual info would be grand^^

Yes, I just tried it. My editor is set to Visual Studio. The problems are still there. Only visual studio is giving the error, not unity. When I run the game in unity it plays just how I intended it to run, but visual studio doesn’t like it and floods me with errors not understanding UnityEngine.UI; So it isn’t stopping my game from working but it is getting in the way of important errors that I need to see. Thats why I originally asked if I could disable them somehow.

@BetrayedPickle

Hey, Program Manager on the Visual Studio Tools for Unity team here. That’s not an issue I’m aware of - can you share what you found that led you to believe it was a bug?

Which version of VS and Unity are you using?

You also mentioned that Unity plays just how you intended, but that VS was stopping the game from working - what do you mean?

@John_MSFT I think it is a bug because I read on some forum somewhere that it was. Basically visual studio doesn’t recognize Unity Engine UI. I also think it is a bug because Unity doesn’t care and runs the code how it is intended to run but visual studio gives errors. It isn’t stopping the game from running, but it is very annoying to be flooded with invalid errors. I’m pretty sure you can do a google search for this and it will be on other forums.

I am using 2019.3.12f1 for Unity, and Visual Studio Community 2019.

@BetrayedPickle

I’m not aware of any bugs with this, but there are some scenarios where that could happen but it’s hard to tell without more info & seeing the errors.

I can recommend a few things.

  1. Follow the steps here to make sure the Visual Studio 2019 is set as the external editor (I think you did this already) Install & configure Visual Studio Tools for Unity | Microsoft Learn
  2. Click the Regenerate project files button in that menu item and re-open VS.
  3. Confirm VS is opening the Unity project correctly - you should see “Attach to Unity” at the top if it’s working. 6124028--667451--upload_2020-7-23_17-8-50.png
  4. Make sure VS 2019 is up-to-date. Use Help > Check for Updates in VS to confirm.
  5. None of that works, can you paste the exact error or screenshot?

it says vs is up to date. and yes i already set vs to external editor

@John_MSFTbasically i have 3 different scripts that make a checkmark ui pop up on your screen if you pick up an object. this is my first game so im just trying simple stuff. but those three scripts are for the three checkmarks you get so i have 2 errors per script which is flooding my error list so i cant see important errors how can i get rid of this?

You should post your scripts, using the code tags.

Just in case, make sure the Visual Studio Editor package is installed in Unity.

What you can also do is creating a new empty project and import in it your project Assets folder; see if the errors still show up.

Just a heads up, the Visual Studio package isn’t available (or necessary) for Unity 2019.3.

Thanks for the info. :slight_smile:

Why is it (normally) systematically installed in every new project whatever the version of Unity then?

It’s not for Unity 2019.x

If you use Unity 2020.x it will be used.

Have you tried entering “using UnityEngine.UI” at the top of your scripts?

Have you tried not necroposting 2.5 year old threads?

1 Like