Search Unity

Animation C# jobs in 2018.2a5

Discussion in 'Animation' started by Mecanim-Dev, Apr 4, 2018.

  1. fherbst


    Jun 24, 2012
    Not sure what you mean with "correct", documentation clearly states "world position" while it's not - I'm not talking about a parent to the Animator but a parent to those bones inside the Animator hierarchy.
    Also, the exact same method seems to work fine for elements in that chain (they are using Get/SetGlobalTR to update, and each child gets the right parent position), so there must be some way to make the job aware of the parent transform...

    Edit: nearly all useful effects need some world space awareness, be it looking at a point, a pos/rot damper, foot placement, ...
    Last edited: Nov 6, 2019
    awesomedata likes this.
  2. Alex_StudioDrydock


    Jan 16, 2019
    Hi, is there a way to create the TransformStreamHandles for a rig that has "Optimize Game Objects" enabled on import?
    littlepolygon and fherbst like this.
  3. littlepolygon


    Jul 7, 2013
    I'm also working on collision integration with Animator/PlayableGraph (sample gif). I started a new thread, but then was pointed at this thread from twitter. TL;DR Both Physics.Raycast and RaycastCommand.ScheduleBatch are main-thread-only, which is a blocker on doing a terrain-fixup-ik-playable. Any word from internal devs on whether this kind of support is in the pipeline?
  4. Mecanim-Dev


    Unity Technologies

    Nov 26, 2012
    Hi @littlepolygon

    Unfortunatelly no, not in the current tech. The only ways to do that right now is to wait until LateUpdate, do your raycast and solve your IK from the main thread.

    We did try to improve the integration with physics in the current tech but we couldn't do it because the system was not design for multithreading and we can't change it without breaking all the current user projects.

    But for dots we want to support raycast from our animation graph which is multithreaded.
  5. littlepolygon


    Jul 7, 2013
    I've been confused about DOTS for a while, and information is hard to verify -- does it live alongside legacy interfaces, or is it effectively a different project-type/engine under the unity "umbrella"?
  6. Mecanim-Dev


    Unity Technologies

    Nov 26, 2012
    it live alongside legacy interfaces, we do have an hybrid mode to mix both DOTS and legacy unity while we are working on completing the dots tech.

    So today in unity editor you can download all the dots package and start to play with them and see how the interact all togheter.

    This is not production ready and there is a lot of tools missing.
    Do not expect to much and stability because it still early.
    littlepolygon likes this.
  7. CptKen


    May 30, 2017

    I'm trying to use animation jobs to apply some animation logic in between the 'base animation system' (usually mecanim) and the 'Animation Rigging' playable graph (or any other second graph for that matter).

    To do this I've made a second playable output with my AnimationScriptPlayable running an animation job on it as shown in the below image:

    The code that I used to set this up is at the bottom of this post. However, it's mostly standard playable graph code. The only thing different I've done compared to usual, is that I use the following function to ensure that the animation stream from the first playable output is routed to my second output. From what I've seen, this seems to be the way the animation rigging package routes the stream to different layers.

    Code (CSharp):
    1. PlayableOutput.SetAnimationStreamSource(AnimationStreamSource.PreviousInputs)
    Now for the most part this works fine and the animation stream coming in is indeed from the first. However, the moment I set a position or rotation on a transform stream handle here, it changes the entire animation. It doesn't matter what I set even something as simple as setting the position of the hips to the same position that they are already in, adversary affects every transform in the model. HipHandle.SetPosition(stream, HipHandle.GetPosition(stream));

    You can see it in this image. The left character is normal and the right has my animation script. These animations should look exactly the same but for some reason the entire upper body is more bent over, the front leg is raised higher and the back leg is a little more forward than it should be. This all by simply setting the hip position to the exact same position as it was already in [HipHandle.SetPosition(stream, HipHandle.GetPosition(stream));]


    Is there something I am doing wrong here in the setup. I don't know why the entire hierarchy is changing even though technically I'm changing nothing in this test animation job. Should I be making a second playable graph for this?

    Code (CSharp):
    2. m_playableGraph = m_animator.playableGraph;
    4. var playableOutput = AnimationPlayableOutput.Create(
    5.      m_playableGraph, "StrideWarpOutput", m_animator);
    7. var strideWarpIKAnimJob = new StrideWarpIKJob()
    8. {
    9.      SpeedWarp = 1f,
    10.      CharPositionY = transform.position.y,
    11.      Offset = m_baseOffset,
    12.      DeltaTime = Time.deltaTime,
    13.      Hips = m_animator.BindStreamTransform(m_hips),
    14.      LeftThighJoint = m_animator.BindStreamTransform(m_leftThigh),
    15.      RightThighJoint = m_animator.BindStreamTransform(m_rightThigh),
    16.      LeftLowerLegJoint = m_animator.BindStreamTransform(m_leftLowerLeg),
    17.      RightLowerLegJoint = m_animator.BindStreamTransform(m_rightLowerLeg),
    18.      LeftFoot = m_animator.BindStreamTransform(m_leftFoot),
    19.      RightFoot = m_animator.BindStreamTransform(m_rightFoot),
    20. };
    22. m_animScriptPlayable = AnimationScriptPlayable.Create(
    23.      m_playableGraph, strideWarpIKAnimJob, 0);
    25. m_animScriptPlayable.SetProcessInputs(true);
    26. playableOutput.SetSourcePlayable(m_animScriptPlayable);
    27. playableOutput.SetAnimationStreamSource(AnimationStreamSource.PreviousInputs);
    28. playableOutput.SetWeight(1f);
    UPDATE: Same problem if I move my playable output to a second playableGraph
    UPDATE: Tested in 2019.1.14f and 2019.3.0f5, results are the same.
    Last edited: Jan 23, 2020
  8. Mecanim-Dev


    Unity Technologies

    Nov 26, 2012
    Hi, there is nothing obvious at first glance that would yield this behaviour.

    We are using the same technic in timeline to drive any kind of animation rig and to keyframe it and we don't see any pose change when we set some value in the stream. So I don't understand why you get this result.

    Could you log a bug with a project exposing this issue? that would help us to understand what is going on
    CptKen likes this.
  9. CptKen


    May 30, 2017
    Thanks for the reply. Cheers, I'll log a bug report replicating this issue.
    Last edited: Feb 6, 2020
  10. Kybernetik


    Jan 3, 2013
    I recently reported two bugs relating to Animation Jobs which I haven't received any response about and I'm wondering if I might just be using the system wrong.
    • Case 1218166 - Jobs are playables, but they don't actually run when I simply connect them to another playable in the graph. They only run if I connect them directly to an AnimationPlayableOutput.
    • Case 1220865 - Only the first PropertyStreamHandle I create seems to work properly. I made the following class:
    Code (CSharp):
    1. public sealed class AnimatedProperty
    2. {
    3.     public AnimatedProperty(PlayableGraph graph, Animator animator, string name)
    4.     {
    5.         var property = animator.BindStreamProperty(animator.transform, typeof(Animator), name);
    7.         var playable = AnimationScriptPlayable.Create(graph, new FloatJob() { property = property });
    8.         playable.Pause();
    10.         var output = AnimationPlayableOutput.Create(graph, name, animator);
    11.         output.SetSourcePlayable(playable);
    12.     }
    14.     private struct FloatJob : IAnimationJob
    15.     {
    16.         public PropertyStreamHandle property;
    17.         public float value;
    19.         public void ProcessRootMotion(AnimationStream stream) { }
    21.         public void ProcessAnimation(AnimationStream stream)
    22.         {
    23.             value = property.GetFloat(stream);
    24.             Debug.Log(value);
    25.         }
    26.     }
    27. }
    If I create one of them, it can properly read the specified value. But if I create a second one it always logs 0. And if I swap them around, it's always the first one to be created that works and the second doesn't.

    Any suggestions?
  11. sdf


    Sep 6, 2012
    Is there way to integrate the animation ik job samples into timeline or run in editor? Any suggestion is welcome。
  12. jaeeunpark


    Feb 3, 2020
    I'm working on modifying a bunch of bones(transform) in runtime.
    Animation job is proper way to achieve this with acceptable performance cost, but there is wasting cost in AnimationScriptPlayable.ProcessRootMotion. Even though it is blank function.

    Can I prevent invoking processRootMotion? 1.4ms is too much to waist.

    I'm attaching profiling result.