Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

[dots] Adding Rootmotion to MyFirstClipExample

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

  1. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    I'm 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 )

    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. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    Am I asking in the wrong forum? Or is the api going to change soon for this particular question?
     
  3. OlivierDionne

    OlivierDionne

    Unity Technologies

    Joined:
    Apr 6, 2018
    Posts:
    10
    Sorry @thelebaron for the late reply. The root motion API is indeed in the process of being changed and the RootMotionNode you mention is being deprecated. Note that DOTS animation package is quite experimental and in a constant state of flux. We haven't updated the public samples with the latest version as well to minimize the rate of changes. We'll make sure to update once it's more stable.
     
    NotaNaN, optimise and thelebaron like this.
  4. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    857
    Thanks, I don't suppose there is an eta? I've been using dots since inject so I am comfortable with flux, I just hope that given some of the backlash to packages that rate of public updates hasnt been reduced. Also is this the preferred subforum to talk about dots animation over the dots forum?