Bizarre "script changes not changing anything" issue ???

This problem totally explained by Bunny, see below…


Have a variable with a string, like

public var message : String = "some text here";

Arrange to show it on the screen. Hit Play. Now, using your text editor change the text of the variable.

public var message : String = "some text here - edited";

When I hit play again, it simply does not change – Unity still seems to “know” only about the previous text.

A total mystery to me, any explanation?

That’s not a bizarre behaviour… Unity will serialize all public variables of your scripts so you can edit the values in the inspector. If you don’t want the variable to be serialized, use the NonSerialized attribute.

copied from comment
You can simply reset your instance by right-clicking at the components header and select Reset. This will erase all serialized data and re initialize the component. If your script has a Reset function, it will be called in this case. Reset is also called for newly added components.

Generally there are 4 types of variables (i’ve omitted static and protected):

Serialized variables:

public var var1 : String = "text1";  // the public keyword can be omitted in UnityScript

@System.SerializeField
private var var2 : String = "text2";

Non serialized variables:

@System.NonSerialized
public var var3 : String = "text1";  // the public keyword can be omitted in UnityScript

private var var4 : String = "text2";

The confusing thing is maybe that Unity automatically serializes public variables.

Another way is to initialize your variables in Start(). Start is called after the component has been initialized.

public var var5 : String;

function Start()
{
    var5 = "text5";
}

Here’re the same examples in C#

Serialized variables:

public string var1 = "text1";

[System.SerializeField]
private string var2 = "text2";  // the private keyword can be omitted in C#

Non serialized variables:

[System.NonSerialized]
public string var1 = "text1";

private string var2 = "text2";  // the private keyword can be omitted in C#

public string var5;

void Start()
{
    var5 = "text5";
}