MonoBehaviours with ScriptableObjects and duplicating`

I have the following classes…

abstract class Animation : ScriptableObject {
  abstract void Play();
}

class MoveAnimation : Animation {...}
class RotateAnimation : Animation {...}

class Button : MonoBehaviour {

  List< Animation > animations;

  void Update()
  {
    if(IsPressed()) {
      foreach(Animation anim : animations)
        anim.Play();
    }

  }
}

This is all currently working properly; when I press the button it plays the animations. Also, I have built a custom editor that allows be to easily add animations to the button.

The problem arises when I duplicate a button in the editor (i.e. Ctrl+D). It creates a new Button but seems to copy not clone the list of animations. So the two seeming different button instances share one list of animations which causes headaches while editing.

The obvious solution is to clone the list of animations (and the object’s inside) but I am not sure how/when to do this. So…

How/when do I handle the cloning of my internal objects when the owning MonoBehaviour has been cloned/duplicated?

The only point where you can hook into the event chain is Reset(). It’s actually the “logical constructor”. It is truly called only once, even for serialized objects. It is only called when an object get its first initialization. So in Reset() you could do something like:

void Reset()
{
    List<Animation> tmp = List<Animation>();
    if (animations != null && animations.Count > 0)
    {
        foreach(Animation A in animations)
        {
            tmp.Add((Animation)Instantiate(A));
        }
    }
    animations = tmp;
}

Not tested but in theory it should work.