Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can I tell the editor to ignore this compile warning? [Answered]

Discussion in 'Scripting' started by Marscaleb, Jun 27, 2014.

  1. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    977
    I have a lot of variables set up to be used later, and the list is growing. And every time I compile my code the editor returns these warning saying "variable such-and-such is assigned but the variable is never used!"

    Is there a way I can tell the editor to not display those warnings? It's gotten to the point where I could miss a new and relevant warning.
     
  2. peterdeghaim

    peterdeghaim

    Joined:
    Apr 10, 2014
    Posts:
    154
    Just put // before the variable until its needed I guess?

    Sorry for the lackluster answer, I dont really know what you can do :/
     
  3. zaxvax

    zaxvax

    Joined:
    Jun 9, 2012
    Posts:
    220
    Did you try those toggles?
    log.png
     
    peterdeghaim likes this.
  4. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    977
    Yeah but that would clear ALL the warnings. It's not too common, but every now and then I write something that generates a warning and not an error, and I don't want to miss it.

    I just want to miss these ones that tell me a variable is never used.
    At least for the foreseeable future.
     
  5. Sharp-Development

    Sharp-Development

    Joined:
    Nov 14, 2013
    Posts:
    353
    Add this to the top of your script.

    #pragma warning disable 0649

    Generally speaking, if you do have a warning you want to ignore, simple look at it. It'll give you a unique warning code aswell. For not assigned variable's it is CS0649. Just put the four numbers into the above pragma and the compiler will ignore them.
     
    NomadKing likes this.
  6. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    It's good practice to do a restore afterwards, though. Warnings are there for a reason, so while you want to suppress them where you're making a deliberate choice, you do want them to appear when you're not doing that.
     
  7. Marscaleb

    Marscaleb

    Joined:
    Jan 7, 2014
    Posts:
    977
    It works! My code was CS0414 so I had to change the number at the end, but it works just like I wanted!

    Oh yeah. I wouldn't be hiding this one if it wasn't for the exact nature of the warning in this circumstance. And even then I'm only hiding it so I don't wind up missing other warnings.
     
  8. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,500
    Indeed, that's the ideal reason to do this kind of thing. I was mostly posting to point out that there was a "restore" option too and that people should generally use it hand in hand with their "disable" calls.