Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Animation C# jobs in 2018.2a5

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

  1. fherbst

    fherbst

    Joined:
    Jun 24, 2012
    Posts:
    675
    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

    Alex_StudioDrydock

    Joined:
    Jan 16, 2019
    Posts:
    8
    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

    littlepolygon

    Joined:
    Jul 7, 2013
    Posts:
    16
    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

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,672
    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

    littlepolygon

    Joined:
    Jul 7, 2013
    Posts:
    16
    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

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,672
    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.

    https://github.com/Unity-Technologies/Unity.Animation.Samples

    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

    CptKen

    Joined:
    May 30, 2017
    Posts:
    210
    Hi,

    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:

    upload_2020-1-23_9-44-49.png
    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));]

    upload_2020-1-23_9-59-54.png

    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):
    1.  
    2. m_playableGraph = m_animator.playableGraph;
    3.  
    4. var playableOutput = AnimationPlayableOutput.Create(
    5.      m_playableGraph, "StrideWarpOutput", m_animator);
    6.  
    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. };
    21.  
    22. m_animScriptPlayable = AnimationScriptPlayable.Create(
    23.      m_playableGraph, strideWarpIKAnimJob, 0);
    24.  
    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

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,672
    @CptKen
    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

    CptKen

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

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,189
    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);
    6.  
    7.         var playable = AnimationScriptPlayable.Create(graph, new FloatJob() { property = property });
    8.         playable.Pause();
    9.  
    10.         var output = AnimationPlayableOutput.Create(graph, name, animator);
    11.         output.SetSourcePlayable(playable);
    12.     }
    13.  
    14.     private struct FloatJob : IAnimationJob
    15.     {
    16.         public PropertyStreamHandle property;
    17.         public float value;
    18.  
    19.         public void ProcessRootMotion(AnimationStream stream) { }
    20.  
    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

    sdf

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

    jaeeunpark

    Joined:
    Feb 3, 2020
    Posts:
    4
    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.
    upload_2020-3-27_19-14-35.png
     
  13. Zzxcv

    Zzxcv

    Joined:
    Oct 31, 2016
    Posts:
    2
    hello.
    is there any way that in FullBodyIk read animation from Animator Component, instead of using only one animation clip?
    i mean this line:
    Code (CSharp):
    1. var clip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Humanoid", "Idle");
     
  14. caste

    caste

    Joined:
    Dec 19, 2012
    Posts:
    7
    Also interesting for me
     
  15. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    1,189
    When the Animation Jobs Samples need to communicate with their job, they always use Get/SetJobData which needs to copy the whole struct around and probably do a bunch of safety checks and other stuff.

    For example, every Update the WeightedMaskMixer needs to tell the job if the
    weight
    changed and modifies the bone weights. It also sets
    job.boneWeights = m_BoneWeights;
    which is actually unnecessary because native arrays function more like a reference type.

    So in my own jobs, I've instead been making read/write fields as native arrays with a single element so the container class can just keep the original job object and access that array element without needing to use Get/SetJobData.

    I'm just wondering if this approach is likely to cause problems. Needing to dispose the arrays adds a bit of complexity, but accessing the data from outside the job is much easier. Is there something I'm missing?
     
    Zzxcv likes this.
unityunity