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

Editor Changing public variables.

Discussion in 'Editor & General Support' started by Lestercodes, Apr 27, 2021.

  1. Lestercodes

    Lestercodes

    Joined:
    Aug 15, 2020
    Posts:
    3
    I have some public variables attached to a Gameobject in my scene. However I have it public for programming purposes not to change it in the inspector. Everytime I start my game in the editor the variable is changed to the value that is in the inspector. This wouldnt be a problem as I can change the value. But I have many scenes in my game and going through and changing them all is a burden. I wish there was a more efficient way to make sure the inspector doesnt have access to changing my variable.

    For clarification
    Code (CSharp):
    1. public List<bool> modelsBought = new List<bool>(4);
    This is one of the variables. In the inspector the size could be 3 for example. Even though I initialized the list with a capacity of 4. When I launch the game the size is changed to the size stated in the inspector which causes all sorts of problems. I couldn't find anything online about this problem so I figured to ask here.

    Code (CSharp):
    1. public List<bool> modelsBought = new List<bool>{false, false, false, false};
    I tried this too but to no avail. The inspector still changed my variable
     
  2. Unity-Harkness

    Unity-Harkness

    Unity Technologies

    Joined:
    May 8, 2019
    Posts:
    5
    Lestercodes likes this.
  3. Lestercodes

    Lestercodes

    Joined:
    Aug 15, 2020
    Posts:
    3