• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by chechoggomez · Dec 16, 2014 at 02:48 PM · animationmecanimrecording

How can I record mecanim animations with value changes on animator.speed?

I need to record animations on mecanim and want also record the animator.speed changes to playback slow motion moments as well.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
5

Answer by chechoggomez · Dec 16, 2014 at 03:36 PM

The animator.speed value is not supported for recording in unity, however you can workaround this by using a separated Animator to record the speed values in a float parameter and then playback both animators and make a correction on the playbackTime by using the recorded value on the speed parameter from the other animator.

Like this :

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class RecordingManager : MonoBehaviour {
     
     public Animator mainAnimator;
     public Animator animatorSpeedRecorder;
     public Button playBackButton;
     public Button recordButton;
     public Text speedLabel;
     public Slider speedSlider;
     private bool isPlayingBack = false;
     private bool isRecording = false;
 
     void Start () 
     {
         animatorSpeedRecorder.SetFloat ("speed", 1.0f);
         speedSlider.value = 1.0f;
         speedLabel.text  = "Speed: "+mainAnimator.speed +"x";
     }
 
     void Update () 
     {
         if(isPlayingBack)
         {
             float time = animatorSpeedRecorder.playbackTime + animatorSpeedRecorder.GetFloat ("speed") * Time.deltaTime;
 
             while(time > animatorSpeedRecorder.recorderStopTime)
                 time -= (animatorSpeedRecorder.recorderStopTime - animatorSpeedRecorder.recorderStartTime);
             
             animatorSpeedRecorder.playbackTime = time;
             mainAnimator.playbackTime = time;
         }
     }
 
     public void OnSpeedValueChanged()
     {
         if (mainAnimator && animatorSpeedRecorder) 
         {
             mainAnimator.speed = speedSlider.value;
             animatorSpeedRecorder.speed = speedSlider.value;
             animatorSpeedRecorder.SetFloat ("speed", mainAnimator.speed);
             speedLabel.text  = "Speed: "+mainAnimator.speed +"x";
         }
     }
 
     public void OnClickRecordingButton()
     {
         if (isRecording) 
         {
             StopRecording ();
         } else 
         {  
             StartRecording ();
         }
     }
 
     public void StartRecording ()
     {
         if (mainAnimator && animatorSpeedRecorder) 
         {
             isRecording = true;
             playBackButton.enabled = false;
             mainAnimator.StartRecording (-1);
             animatorSpeedRecorder.StartRecording (-1);
             recordButton.image.color = Color.red;
             playBackButton.image.color = Color.gray;
         }
     }
     
     public void StopRecording ()
     {
         if (mainAnimator && animatorSpeedRecorder) 
         {
             isRecording = false;
             playBackButton.enabled = true;
             mainAnimator.StopRecording();
             animatorSpeedRecorder.StopRecording();
             recordButton.image.color = Color.white;
             playBackButton.image.color = Color.white;
         }
     }
 
     public void OnClickPlayBack()
     {
         if (isPlayingBack) 
         {
             StopPlayback ();
         } else 
         {
             StartPlayback ();
         }
     }
 
     public void StopPlayback ()
     {
         if (mainAnimator && animatorSpeedRecorder && isPlayingBack) 
         {
             isPlayingBack = false;
             recordButton.enabled = true;
             mainAnimator.StopPlayback ();
             animatorSpeedRecorder.StopPlayback ();
             recordButton.image.color = Color.white;
             playBackButton.image.color = Color.white;
         }
     }
 
     public void StartPlayback (){
 
         if (mainAnimator.recorderStopTime <= 0)
             return;
 
         if (mainAnimator && animatorSpeedRecorder && !isPlayingBack ) 
         {
             mainAnimator.Rebind();
             animatorSpeedRecorder.Rebind();
             recordButton.enabled = false;
             mainAnimator.StartPlayback ();
             animatorSpeedRecorder.StartPlayback ();
             mainAnimator.playbackTime = mainAnimator.recorderStartTime;
             isPlayingBack = true;
             recordButton.image.color = Color.gray;
             playBackButton.image.color = Color.green;
         }
     }
 }
 

Here is the example project: RecordingExample.7z

https://oc.unity3d.com/public.php?service=files&t=05eb07a5c9862dab9315f0d2df35cd84

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Disable auto-record when scrubbing an animation 1 Answer

Mecanim Tutorial lacking animation? 1 Answer

How can I give variation to animation curve in Unity? (Raw mocap data) 0 Answers

Mecanim not updating script when it switches state? 2 Answers

RootMotion is not Working ... 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges