Possible issue between default script value and editor value

Morning all,

just wanted to clarify something before i go any further or raise a ticket.

using Unity Version : 4.6.0b17 (beta)
MonoDevelop Version : 4.0.1

Within a script that is attached to an object in the heirarchy i have the following couple of lines included

    public double gridSpacingX = 0.5;
    public double gridSpacingY = 0.3;

    public int blocksWide = 2;
    public int blocksHigh = 3;

    public Vector3 gridCentre = new Vector3 (0f, 0f, 0f);

then when i go into the editor inspector i can see the default values within there and can change them as i would expect even during runtime.

i thought it might be locallised to a certain datatype, but its all of the above.

however (while out of play mode), if i change the default values in the script and save, these do not update the inspector values, even after a restart of the application.
the default values do show, but only if i remove the script component and reattach, but only that once when the script is initially attached.

I have had a read about, and some are saying it could be the way the script is created and doesnt work as expected when using the ‘addComponent’ button.
so i just created a new script in the heirarchy and then draganddropped, still same result.

just wondering if im doing something obvious or has this been raised before and i cant find it.

Cheers
DaZ

Unity will serialize all the public variables with there values you can see in the inspector. If you recompile or change the script unity will only initialize new variables , leaving the old once unchanged.
Do you need the variable public for viewing and changing it in the inspector? Than change the the default value in the inspector.
You just need the value to be public to have a way to access them from another script , use the NonSerializable attribute
to to prevent unity form Serializing it. That way unity will not save the value and will always take the value form the script
http://docs.unity3d.com/ScriptReference/NonSerializable.html

1 Like

Ah, cheers, my apologies it is me not fully understanding their interaction.
thank you for the link ill make sure to have a good read.