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

How is this possible? (Unity Inspector variable not working properly)

Discussion in 'Scripting' started by Yarbius, Aug 22, 2015.

  1. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    I had something VERY weird happen today. I had a couple of return statements at the beginning of routines to show and hide a tooltip so that I could disable them. Our artist wanted to be able to have them on so I did something VERY simple and I cannot get it to work.

    I added a variable...
    Code (csharp):
    1. public bool disableItemTooltips;
    To the script then changed the tooltip routines....
    Code (csharp):
    1.  
    2. public void ShowTooltip(GameObject slot)
    3. {
    4.     if (disableItemTooltips)
    5.     {
    6.        return;
    7.      }
    8.     // Code to show the tooltip
    9. }
    No matter what I do in the inspector this does not work (the variable is ALWAYS true, even if I initialize it with = false)
    Changing it in the inspector does nothing to the value

    The only way I have been able to make it false is by initializing it as false and readonly

    I had this issue on two different PCs so I am totally stumped

    Ideas?
     
  2. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    The problem definitely isn't with this code. I feel like if it still changes with the readonly statement then it should throw an error. Nonetheless, select the variable and press shift command Y to see all the other areas its being referenced.
     
  3. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You could quite possibly be looking at different variables.
     
  4. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    I have used "Find all references" in VS and it is definitely not referenced anywhere else and is referenced everywhere it should be. It used to be called disableTooltip but I renamed it in case it was hiding another variable that VS was not showing. I am going to try moving the variable into my game manager class because the script is attached to a GUI element on a canvas and I have seen some other wonkiness with GUI related scripts.
     
  5. Yarbius

    Yarbius

    Joined:
    Apr 29, 2014
    Posts:
    22
    OK so I moved the variable to the GameManager script and everything works as expected. There seems to be some ugly bugs regarding scripts attached to GameObjects parented to a GUI Canvas.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Any major bugs will set half the community screaming. If it's just you finding them it's probably user error. Most likely this:

     
  7. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Upload your scene. I have a feeling adding speculation isn't going to help
     
    Kiwasi likes this.