Variable Bug in Unity found

I have tested some small projects and during testing some scripts, I have found a Bug.

-When I write a Javascript and set a variable (and save the script before):

var Test=9;

-add the script to a GameObject, so that you see the value of GameObject in Inspector. (=9)

-now start the scene

-stop the scene

change the var now in script to:

var Test=10;

and save the script file. Now the Value in Inspector Test= is still 9!! Also after starting the scene.
I must change the value in Inspector separately for the attached Game Object.

It’s a Bug or a Feature ? :slight_smile:

It’s a feature. It would be extremely annoying if it didn’t work that way…would you really want your scripts overwriting your inspector values every time you re-saved them?

–Eric

but this is bad.

When I now want change a variable in script, I must then change all the Values in attached GameObjects ?
It’s big work if your make a big project and very dangerous.

It must be possible to disable this feature or ?

It’s hardly bad; it’s the way Unity is supposed to work. One of the major features is rapid development, where you can quickly tweak values in the inspector to get results without having to recompile scripts all the time. It is not possible to disable this behavior.

–Eric

It would nevertheless be good if one had the possibility to attaching the variable local or Global on GameObjects

example:

var Test=10;
@script GlobalOnGameObject=false;

Just use a loop with FindObjectsOfType(// name of your script)
if you ever need to change everything at once like you’re talking about. I don’t find it useful that often, but you can do it like this when you need it.

You can also just use a private variable if you want the script to have 100% control over a variable’s default value, or assign its starting value in Awake().

Edit: … as illustrated in the next post down. :stuck_out_tongue:

You seem confused by the Inspector. If you want a per-object variable with a single source, try:

static var something:float = 2.0;

private var mySomething:float;

function Start()
{
   mySomething = something;
}

or just:

var whatever:float;

function Start()
{
   // reset it here
   whatever = 2.0;
}

Or simply use @HideInInspector() to not serialize the variable:

@HideInInspector()
var something:float = 2.0;

What are you doing in the abstract, though? Seems like your system is oddly-designed to begin with if you need this…

Awake, OnEnable, and Update, with

@script ExcecuteInEditMode

can all be nice that way.

OnDrawGizmos works without having to use the attribute, as well.

thanks guys for the suggestions. I’ll try it. :slight_smile:
I’m coming from C++ Ogree and that is new for me with inspector. :lol:
I must get used to the mode of operation first