Search Unity

Bug Disable errors for a script

Discussion in 'Scripting' started by BetrayedPickle, Jul 22, 2020.

  1. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    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?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
  3. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    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.
     
  4. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    What is .Net and how do I go to its Edit tab
     
  5. Deleted User

    Deleted User

    Guest

    Is the Unity UI package installed in your project?

    Capture d’écran_2020-07-22_20-27-01.png
     
  6. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    yes, only visual studio is giving the error not unity
     
  7. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    Maybe the way i presented it was a bit unclear but it's both Unitys' menu edit. I just marked where to find what.
     
  8. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    @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
     
  9. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,605
    So.. have you tried that? And set your editor to VS? Are the problems gone? Some actual info would be grand^^
     
  10. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    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.
     
  11. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @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?
     
  12. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    @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.
     
  13. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    @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) https://docs.microsoft.com/en-us/vi...19#configure-unity-for-use-with-visual-studio
    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. 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?
     
  14. BetrayedPickle

    BetrayedPickle

    Joined:
    Mar 30, 2019
    Posts:
    119
    it says vs is up to date. and yes i already set vs to external editor



    upload_2020-7-23_14-17-31.png

    @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?
     
  15. Deleted User

    Deleted User

    Guest

    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.
     
  16. John_MSFT

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    Just a heads up, the Visual Studio package isn't available (or necessary) for Unity 2019.3.
     
  17. Deleted User

    Deleted User

    Guest

    Thanks for the info. :)

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

    John_MSFT

    Microsoft Employee

    Joined:
    Feb 21, 2018
    Posts:
    118
    It's not for Unity 2019.x

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

    tryano1

    Joined:
    Apr 13, 2020
    Posts:
    3
    Have you tried entering "using UnityEngine.UI" at the top of your scripts?
     
  20. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Have you tried not necroposting 2.5 year old threads?
     
    Yoreki likes this.
  21. tryano1

    tryano1

    Joined:
    Apr 13, 2020
    Posts:
    3
    You're doing the same thing. I'm just here sharing some advice. Nothing wrong with me doing so for a post that I knew or did not know was 2.5 years old, even so that's not very wrong for that span of time. Though, you have provided nothing, and I'm not even hurting you by just suggesting something productive, yet you still seem insulted. Quite sad, don't you think?

    Edit: When I saw my alerts had a notification, I was hoping it was a valuable and productive answer to one of my questions. But, I was wrong, it was just some guy who wanted to nitpick at the fact that I came a bit late to the party. They didn't even provide any sort of question/answer to anything said in this post! I'm actually hysterically laughing while I'm writing this. This is literally a Unity thread, made for asking a answering questions. And here you go, being pissed off by someone trying to be productive.

    I hope you change for the better,
    tryano
     
    Last edited: Feb 4, 2023