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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Unity is reporting certain warnings as compiler errors

Discussion in 'Scripting' started by ArachnidAnimal, Oct 17, 2015.

  1. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I realize you cant declare a Vector3 to be constant, however when you put the following code in random locations in a C# script, you get bizzare unrelated compiler errors:

    Code (csharp):
    1.  
    2. const Vector3 test = Vector3.zero;
    3.  
    results in the following compiler error:

    compilererrors.png

    This is a warning being reported as a compiler error. The actual compiler error is not reported.
    I think this is a bug. Can anyone confirm this? Using unity 5.2.1p2
    j
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
  3. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
  4. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Hm. True



    It errors for me before i even save.
    But honestly, i dont expect anyone will care
    "Oooh please fix this bug which happens when i do this thing I'm not supposed to do"
     
  5. fg34

    fg34

    Joined:
    Aug 31, 2015
    Posts:
    6
    It seems you are right. I did notice that sometimes unity wont report certain compiler errors if too many warnings warnings are also generated. Also, MonoDevelop does not flag this as an error for me, I would switch to VS or xamarin.
    For someone who doesn't know that a Vector3 cant be static, I can see why it would be impossible to know what the problem was in this situation. I would do a bug report, It couldnt hurt
     
  6. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Vector3s can be static. Any value or reference type can be static. Only basic values can be constant.
     
    hippocoder likes this.
  7. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Vector3.zero is actually shorthand for new Vector3(0, 0, 0) so obviously it can't ever be a const. As for errors being meaningful, it requires the developer to give the errors meaning. If you want it to be meaningful, file a bug.

    Its terribly low priority though.
     
  8. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    Maybe I wasn't clear enough as to what the issue is, because I don't think people are understanding me. So I'll re-explain and re-assign the title of the thread:
    "Unity is reporting certain warnings as compiler errors".
    The actual compiler error isn't shown in the console.

    It is apparent now it is clearly not a low priority issue for me. The same issue happens for me with this compiler error: https://msdn.microsoft.com/en-us/library/ekh0s42s.aspx
    Unity is reporting warnings as compiler errors. The error in the console is clearly not a compiler error, but Unity is considering this to be compiler error. This happens with "const Vector3", among other types of compiler errors.
    j
     

    Attached Files:

    Last edited: Oct 18, 2015
  9. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    I've never looked/found it in Unity, but I know there's a setting that treats warnings as compiler errors. Might be a compiler directive.
     
    ArachnidAnimal likes this.
  10. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I searched the options and can't find a setting for this. This never happened before so I don't know why this happening now all of a sudden. Do you happen to know the setting?

    I do have almost 80 warnings generated at compile time, but alot of them are Asset store related warnings. Im not sure if the number of warnings has something to do with it right now.
    Thanks.
     
    Last edited: Oct 18, 2015
  11. lordofduct

    lordofduct

    Joined:
    Oct 3, 2011
    Posts:
    8,380
    I've also seen times where the unity editor displays the wrong error when there are compiler issues.

    I've never been able to work out the pattern for it, since if I place the actual offending line of code (say your const Vector3) in a completely different class, the error will report correctly.

    Which is why if I put your const Vector3 into my project I get the correct error:
    error_01.png

    Like I said though, I've never been able to hammer out any pattern to it in any way. Nor do I really use the unity editor for checking my compiler errors. So I never bothered to issue a bug about it.
     
    ArachnidAnimal likes this.
  12. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    @lordofduct

    Feeling I've run into the same issue once or twice. Cant remember what code gave me that problem though.
     
    ArachnidAnimal likes this.
  13. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    It seems to be very reproducible for me for certain compiler errors, but not others. So I guess for now I'll have to rely on the actual MonoDevelop editor to flag errors. Right now I don't even have the "source analysis" enabled for MonoDevelop, because I only relied on the Unity console window, up until now.