setting double in editor vs setting it in script (the latter doesn't work)

Hi this question is propably verry simple and im just missing something,

how do i set a double variable in script to say 0.00434782 ?

It works if i set it in Editor but not when i set it in script

I tired :

public double AstroidFieldDensity = 4.347826086E-3;
public double AstroidFieldDensity = (double) 0.004347826086f;
public double AstroidFieldDensity = 0.004347826086;

Your code does work. However since your variable is public it is serialized. You assign your default value when the object instance is created. Field initializers are executed even before the constructor runs. However deserialization happens way after the object has been created. So if you don’t want to set this value in the editor but only inside the script, make it private or add the NonSerialized attribute to your variable

private double AstroidFieldDensity = 4.347826086E-3;

// or
public double AstroidFieldDensity = 4.347826086E-3;

However if you want the values to be editable in the editor you can’t set them from script that way. You can overwrite the serialized value inside Awake or Start. However this would make it pointless to have it serialized.