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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[Animation] Adding Rootmotion to MyFirstClipExample

Discussion in 'DOTS Animation' started by thelebaron, May 15, 2020.

  1. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Trying to get root motion to work with the MyFirstAnimationClip example from the HDRP animation samples repo. Going by how the AnimationControllerGraph & ConfigurableClipGraph demos set up their graphs, I'm making the assumption that all of this is contained to the graph setup(but I'd obviously like to know if this is wrong).

    Graph steps:
    Add a rootmotion node to graph.
    Connect "ClipPlayerNode" to the "RootMotionNode"
    Connect "RootMotionNode" to the "EntityNode"
    Then copying the same setup as the AnimationControllerGraph, ConvertLTWto4x4Node, ConvertLTWto4x4Node into RootMotionNode etc

    With this, the entity moves, but it just goes in a diagonal, and doesn't really appear to be related to root motion of the animation at all.
    Gif of what happens(had to pause and step because it flies off pretty quickly)
    https://i.imgur.com/tA5Dd8b.gifv

    Here's what the converted entity looks like with the animation looking correct(though no rootmotion) https://i.imgur.com/FprYoZr.gifv

    Graph setup code:
    (full code, code below starts at ln 147 - https://gist.github.com/thelebaron/7f3a61814fa30dad049d2e7bd969f202 )

    final note - Id really love a dedicated sticky thread or subforum for animation
    Code (CSharp):
    1.        
    2.  
    3. static PlayClipStateComponent CreateGraph(Entity entity, NodeSet set, ref Rig rig, ref PlayClipComponent playClip) {
    4. var data = new PlayClipStateComponent
    5. {
    6.     EntityNode     = set.CreateComponentNode(entity),
    7.     DeltaTimeNode  = set.Create<DeltaTimeNode>(),
    8.     ClipPlayerNode = set.Create<ClipPlayerNode>(),
    9.  
    10.     RootMotionNode             = set.Create<RootMotionNode>(),
    11.     LocalToWorldToFloat4x4Node = set.Create<ConvertLocalToWorldComponentToFloat4x4Node>(),
    12.     Float4x4ToLocalToWorldNode = set.Create<ConvertFloat4x4ToLocalToWorldComponentNode>()
    13. };
    14.  
    15. // Connect kernel ports - TYPE, SOURCE, DESTINATION
    16. set.Connect(data.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, data.ClipPlayerNode, ClipPlayerNode.KernelPorts.DeltaTime);
    17. //set.Connect(data.ClipPlayerNode, ClipPlayerNode.KernelPorts.Output, data.EntityNode); //old
    18.  
    19. set.Connect(data.ClipPlayerNode, ClipPlayerNode.KernelPorts.Output, data.RootMotionNode, RootMotionNode.KernelPorts.Input);
    20. set.Connect(data.RootMotionNode, RootMotionNode.KernelPorts.Output, data.EntityNode);
    21.  
    22. // Root motion nodes
    23. {
    24.    
    25.     set.Connect(data.EntityNode, data.LocalToWorldToFloat4x4Node,ConvertLocalToWorldComponentToFloat4x4Node.KernelPorts.Input, NodeSet.ConnectionType.Feedback);
    26.    set.Connect(data.LocalToWorldToFloat4x4Node, ConvertLocalToWorldComponentToFloat4x4Node.KernelPorts.Output, data.RootMotionNode, RootMotionNode.KernelPorts.PrevRootX);
    27.    set.Connect(data.RootMotionNode, RootMotionNode.KernelPorts.RootX, data.Float4x4ToLocalToWorldNode, ConvertFloat4x4ToLocalToWorldComponentNode.KernelPorts.Input);
    28.    set.Connect(data.Float4x4ToLocalToWorldNode, ConvertFloat4x4ToLocalToWorldComponentNode.KernelPorts.Output, data.EntityNode);
    29. }
    30.  
    31. // Send messages to set parameters on the ClipPlayerNode
    32. set.SetData(data.ClipPlayerNode, ClipPlayerNode.KernelPorts.Speed, 1.0f);
    33. set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Configuration, new ClipConfiguration { Mask = ClipConfigurationMask.LoopTime });
    34. set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Rig, rig);
    35. set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Clip, playClip.IdleClip);
    36.  
    37. set.SendMessage(data.RootMotionNode, RootMotionNode.SimulationPorts.Rig, rig);
    38. set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Rig, rig); // ? do i need this?
    39.  
    40. return data;
    41. }
    42.  
     
  2. Ommicron

    Ommicron

    Joined:
    May 15, 2020
    Posts:
    47
    ?
    those are all the data flow nodes i had to connect in the set to get it to work
    Code (CSharp):
    1. static PlayClipStateComponent CreateGraph(Entity entity, NodeSet set, ref Rig rig, ref PlayClipComponent playClip)
    2. {
    3.     var data = new PlayClipStateComponent
    4.     {
    5.         DeltaTimeNode = set.Create<DeltaTimeNode>(),
    6.         ClipPlayerNode = set.Create<ClipPlayerNode>(),
    7.         EntityNode = set.CreateComponentNode(entity)
    8.     };
    9.  
    10.     // Connect kernel ports
    11.     set.Connect(data.DeltaTimeNode, DeltaTimeNode.KernelPorts.DeltaTime, data.ClipPlayerNode, ClipPlayerNode.KernelPorts.DeltaTime);
    12.     set.Connect(data.ClipPlayerNode, ClipPlayerNode.KernelPorts.Output, data.EntityNode);
    13.  
    14.     // Send messages to set parameters on the ClipPlayerNode
    15.     set.SetData(data.ClipPlayerNode, ClipPlayerNode.KernelPorts.Speed, 1.0f);
    16.     set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Configuration, new ClipConfiguration { Mask = ClipConfigurationMask.LoopTime });
    17.     set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Rig, rig);
    18.     set.SendMessage(data.ClipPlayerNode, ClipPlayerNode.SimulationPorts.Clip, playClip.Clip);
    19.  
    20.     return data;
    21. }
     
  3. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    Sorry but thats the exact same code from the example which doesnt include root motion?
     
  4. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    825
    @hippocoder could this get moved to the animation previews forum? maybe thats a better place for this question