Unity Inspector overwritting my variables

I have public variables and Color values that were previously set using the Inspector menu. But now I’m setting the same variables through script, the old Inspector values are still overwriting my script defined values! How can I remove the Inspector values? I tried Reset option on the menu but it’s still the same.

I’ve spent hours debugging my script only to realize the Inspector is the culprit! Any solutions besides renaming my variables?

Thanks

Make them private.

Thanks but I need them to be public to be accessible from another script of mine. :frowning:

Create a getter function. Possibly setters if you need them.

C#

private Color myColorValNotInInspector;

public Color ColorVal {
    get {
        return myColorValNotInInspector;
    }
}


// In another script...
Color color = theScript.ColorVal;

UnityScript

private var myColorValNotInInspector : Color;

public function GetColorVal () : Color {
    return myColorValNotInInspector;
}

// In another script...
var color : Color = theScript.GetColorVal ();

http://docs.unity3d.com/Documentation/ScriptReference/NonSerializable.html

You can use the HideInInspector function / tag / idk…

The Variable will still be public but no longer viable in the inspector.

This is another solution, which will likely serve your purpose. However if your variable is something that shouldn’t be set at any time, and you have only made it public in order to access it in other scripts, what I have proposed would fit nicely.

Thanks everyone! Looks like using a getter function is the way to go. Cheers :slight_smile: