Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Animation Snapshot

Discussion in 'Scripting' started by davej256, Apr 28, 2023.

  1. davej256

    davej256

    Joined:
    Nov 11, 2022
    Posts:
    16
    Let's imagine I have two computers. Computer A and Computer B.

    On Computer A, I'm running a regular animation using a blend tree. At a specific frame, I want to package up data about the animation in that 1 frame, and send it to computer B. On computer B, I want to recreate the pose exactly.

    There's basically no information about this on the internet, but I have something close.

    In the Blend Tree, there's a "Motion Time" parameter option. If you enable this and set it up, it allows you to set the exact time alpha. By using Motion Time, and my other parameters, I can recreate the pose exactly.

    The problem: When Motion Time is active, the animation does not play by itself. The only real option here is to either a.) step it manually by myself (unideal) or b.) use the AnimatorController to add/remove parameters which is still really janky and permanently alters the parameters even after I've stopped playing.

    Is there a better way of solving this problem? Sending position/rotation data is not an option.
     
  2. davej256

    davej256

    Joined:
    Nov 11, 2022
    Posts:
    16
    Edit: I think I found out how it works.

    Code (CSharp):
    1.    
    2.  AnimatorController animatorController = (AnimatorController)transform.Find("...").GetComponent<Animator>().runtimeAnimatorController;
    3.  
    4. // timeParameter is the BlendTree (or any other animation state) MotionTime parameter name. Of course the docs mention nothing of this.
    5. animatorController.layers[0].stateMachine.states[0].state.timeParameter = "MotionTimeParamName";
    6. // timeParameterActive allows you to seamlessly enable/disable the MotionTime setting. Again, docs mention nothing of this being mapped to MotionTime.
    7. animatorController.layers[0].stateMachine.states[0].state.timeParameterActive = true;
    Took me about 6 hours now to figure out what should have been a trivial task. Hopefully this helps anyone in the future searching for this.

    Late Edit: But this doesn't work. AnimatorController is inside an editor class. Does not compile. Using the (non motion time) blend parameters for the blend tree and setting the animator speed to 0 while setting the normalized time using .play might be the correct/only way to achieve this.
     
    Last edited: Apr 29, 2023