So, what I want to make is a tool to assign some object a sequence of steps of animations (each step may have several animations).
And the way I do it is to have an array of instances of custom class, and the custom class has a property which stores an array of AnimationClip, and a float property determines when these animations stop, its default value is 1f which means they stop at 100% of their length.
Now the weirdness is, if I assign the array of custom class instances in the declaration using code block 1(below) it will work well, but if I only declare this array in code and let the user extend it/assign values at runtime, using code block 2(below), the float property will lose its default value and be assigned 0. And in this case the user will be very likely to forget setting it and it will look like a bug.
Here are the codes:
code block 1
[System.Serializable]
public class AnimationStep {
public AnimationClip[] animations;
public float playNextInPercent = 1f;
public AnimationStep() {
}
}
public class AnimationSequence : MonoBehaviour {
public AnimationStep[] steps = new AnimationStep[3];
}
This will work well.
code block 2
[System.Serializable]
public class AnimationStep {
public AnimationClip[] animations;
public float playNextInPercent = 1f;
public AnimationStep() {
}
}
public class AnimationSequence : MonoBehaviour {
public AnimationStep[] steps;
}
In this case when the user assign values to “steps” the “playNextInPercent” in each “step” will be 0, which means the playNextInPercent lost its default value of 1.
So my question is, why it loses the default value if it’s created at runtime by the user in inspector? And is there anyway to change this?
Thanks!
Pine