Search Unity

animation event can not trig in editor mode

Discussion in 'Animation' started by dreamerflyer, Aug 8, 2014.

  1. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    Hi all,How can i trig the animation event in editor mode ,not in play mode?
     
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Hi dreamerFlyer,

    You cannot trigger AnimationEvent while you are not in play mode

    Why do you want to do this in editor mode?
     
  3. dreamerflyer

    dreamerflyer

    Joined:
    Jun 11, 2011
    Posts:
    927
    because of i want to preview the all the effect ,for example show the particle system at some animationNormaltime,or when gameobject moving in one animation ,change it,'s animationClip at the same time.And When i use AnimationMode.SampleAnimationClip,it only can control one animationclip,can not control mutil animation at the same time.So ,I can not preview all the effect at the same time.
     
    Last edited: Aug 12, 2014
  4. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    SampleAnimationClip() won't trigger AnimationEvent, it a simplified path like you said that sample only one clip.

    The Animator can record and playback animation, but it does only record the animator, so if the animator trigger some other Unity system like Particule system, particules won't playback.

    We do exactly the same thing in the avatar previewer for transition and animation clip preview.

    First you need to set the animator in record mode and then resample for the length that you need.

    Code (CSharp):
    1. float stepTime = 0.02f;
    2. float currentTime = 0.0f;
    3. animator.StartRecording(-1);
    4. animator.Update(0.0f);
    5. while(currentTime  < 2.0f)
    6. {
    7.     animator.Update(stepTime);
    8. }
    9. animator.StopRecording();
    and then you can playback what you just recorded, including AnimationEvent.

    Code (CSharp):
    1. animator.StartPlayback();
    2. ...
    3. animator.playbackTime = myTime;
    4. animator.Update(0);
    5. ...
    6. animator.StartPlayback();