c# - Unable to change array size in Inspector variable in Unity? -


from have read how vector "size" set

public color[] teamacolors = new color[4]; 

but when code run looks enter image description here

it doesn't seem matter number put [4], size stays 6. not sure 6 number coming have not set number.

i have tried

 public color[] teamacolors; 

and let array auto populate length, doesn't change 6 either.

it's simply

 public color[] teamacolors; 

but "6" value "won't go away"?

but you've stumbled on "reset" gotchya in unity!

enter image description here

just try different variable name...

public color[] teste; 

see?

enter image description here

there is, working fine. can set size dynamically, long never put size in code.

here secret:

unity "holds on to" serialized values in complicated way.

if set size in code once, unity "remembers" if subsequently change code.

there way reset "inner" value .. famous tiny reset button.

it attached tiny cog symbol.

enter image description here

the critical rule remember this:

never, ever, have default value in code public variables in unity!!

public float x;  //  public float x=2f;  // never 

while you're @ it, here's incredibly handy trick. try ...

[header("how this?")] public float x; 

here's cooler one! try it!

[range(2f,4f)] public float x; 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -