Unreal-Root Motion-Issues and Fixes

I have seen constant confusion surrounding what root motion is and whether it works over the network or with NavMesh. After spending some time implementing this, I hope this post might bring some information to light.

Root motion in this context refers to the notion of applying the transformation and rotation information from the root bone of an animation directly to the Character Actor in Unreal.

You can view the Epic docs at https://docs.unrealengine.com/latest/INT/Engine/Animation/RootMotion/

In this sense, root motion replaces the need to calculate the movement in code and instead enables the animation to determine it.

For example, consider a typical zombie walk. Typically, one might play a walking animation and at the same time apply movement to the pawn. An animation without root motion is often referred to as an in-place animation. The animation typically relies on constant linear movement, and as long as the movement applied to the pawn matches that speed, then the feet will not slip and the zombie will appear to walk forward. Of course, sometimes this can be difficult to match up perfectly right, and any increase/decrease in pawn movement speed needs to be accompanied by a matching change in the animation playback speed. Otherwise, this can result in foot sliding e.g. the moonwalk.

To use root motion to drive the movement instead, one first needs to create or obtain an animation with movement and/or rotation applied directly to the root bone, typically done in an animation authoring tool such as max or maya. In addition, many of the assets on the Marketplace include both Root Motion and In-Place animations. When a Root Motion animation is played in unreal, that motion on the root bone is applied to the Character instead of to the root bone. Unreal has already implemented full-support for Root Motion in the Character actor. Thanks Unreal!

So what are the benefits of using root motion? It keeps the collision capsule anchored to the mesh where it should be, it enables you to utilize acceleration and deceleration in your animation, it eliminates foot sliding and other artifacts, and it simplifies the programming work load.

Can I use root motion on my Player-controlled pawn?

Yes — but instead of the joystick axis controlling how much force to apply or directly modifying transformation to apply, instead it controls which animation to play and how fast to play it. Controlling you character == controlling the animation that is playing playing. Want to walk faster? Play the animation to walk faster. Want to turn 90 degrees? Play an animation that turns 90 degrees.

Does it work with vertical root motion? Yes, but remember, your character movement component needs to be flying.

Does root motion work with blending?

Yes, the animations are blended, and the resulting blended transform from the animations on the root are applied.

Can I use root motion for my AI enemies?

Yes — as with a player pawn, the Behavior Tree needs to control what animation is being played.

Does it work with AI MoveTo?

No, MoveTo moves the actual pawn. But there is an alternative: just use the underlying path nodes to orient the agent’s direction. Remember, as long as the pawn is facing the correct direction, root motion will drive it toward that location. So instead of using AI MoveTo, you can use FindPathToActor to generate a list of path points, and use them to orient the direction the agent is facing.

Does root motion over the network?

Is the built-in network correction/client side prediction code utilized?

Yes. Position reconciliation for root-motion driven characters is present in the CharacterMovementComponent. Client side prediction is not really needed, since the location of the actor between network updates is determined by the root-motion from the animation playing.

I created a short tutorial video to illustrate using Root Motion over the network:

Introduction in to Root Motion

This Post was created so I can discuss Root Motion and what lead me in this direction?, what it is and how does it benefit me?. How is Root Motion used?. What issues have I discovered and how did I over-come them?.

As I continue developing my skills in Unreal in conjunction with other programs such as 3DS Max and Substance Painter as-well as Photoshop and in this instance Make Human. As I find they all can work in conjunction with one another, from design to creation to implementation. I decided I wanted to create a Free Running game, a Game where the player could Climb and Hang and Crouch and Roll as they navigate around the Environment. I have some Tutorials below that show how I developed this Blueprint system within Unreal. Additionally I have some screenshots taken from within Unreal showing How I developed this system and shows both the Blueprint and Game-play of the System functioning up until the point of the error discovered.

This slideshow requires JavaScript.

The Images above show the entire system created to allow my Actor to Hang and Climb. The Blueprint functions correctly the error is related to the Skeleton I am using or was using at the time.

The Game-play images above show how far I got the Blueprint and Game-play, they only show the Actor hanging as Climb although Blueprinted would not work or function as it did in the Tutorials, note from the off the Tutorials use the Unreal Mannequin this using the Unreal Skeleton. I was not I was using one created in Mixamo.

What is Root Motion?

Root Motion is a Tool used by Unreal to translate Movement data from an Animation over to a Skeleton using the Root to do this. So to explain if an Actor within Unreal was to perform an Animation as an example Roll, Root Motion would allow the Actor to move and escape his Capsule component and upon Animation completion the Actor will end up where the Animation left off. Without Root Motion he would simply move back to his original Location or not escape the Capsule at all, dependant on whether or not a Root Bone is present. I have included a Link to Unreals Documentation explaining this more thoroughly.

Root Motion Benefits

Climbing Tutorial 1

https://youtube.com/watch?v=4yjcwZLQqlE%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26wmode%3Dtransparent

The Tutorial above is part of a collection of Tutorials aimed at Teaching how to set about creating a Climbing system using the Unreal Mannequin. The Tutorial is very long an complex but he goes in to great detail in these series of Tutorials and fully explains what he is doing what and why.

Climbing Tutorial 2

https://youtube.com/watch?v=BKiSTM-G9pQ%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26wmode%3Dtransparent

Extra Note 1

Both the Tutorials above offer Animation files for the Unreal Actor to allow him to perform both the Ledge Grab Move and the Climb Up Move.

Root Motion Screenshot

Unreal-Root Motion-Issues and Fixes

However a Root Bone must be present for Root Motion to function as intended. I will explain, using the Unreal Actor this bone will be present in the Skeleton, see Image below.

Root Bone-Unreal Skeleton

Unreal-Root Motion-Issues and Fixes

Root Bone Mixamo Rig on Unreal Skeleton

Unreal-Root Motion-Issues and Fixes

Though the same can not be said if you where to use a Mixamo Skeleton. See Image below.

No Root Bone-Mixamo Skeleton

Unreal-Root Motion-Issues and Fixes

Double Root Bone-Alt Make Human Export

Unreal-Root Motion-Issues and Fixes

Below I have also included a collection of Screenshots showing this Root Motion on and off my target Skeleton. My own Mesh and Skeleton created using Make Human and Rigged in Mixamo then edited in Maya and finally imported back in to Unreal.

Unreal Rigged Character Screenshots

What is Mixamo?

Mixamo is an Auto Rigging Software available for free online.

The Software saves time by Weight painting your Uploaded Mesh and Rigs it for you. The free Program also offers a rather large collection of Animations again all available for free. Both of these processes can be really time consuming and can take a long time to perfect. This program can do it in about 2 minutes, so it saves a great deal of time and can do it with little to no set up and limited understanding of how Weight painting and Skeletons work. It is a great program but I found during my development it has one draw back, although this was not always the case. Mixamo removed a previous option of an Unreal export, this would have created a Root Bone, which is no longer present on the Download option you are given, which is a standard FBX Mesh with Skin with no Root Bone.

Other Export options

Unreal-Root Motion-Issues and Fixes

Standard FBX option (present)

Unreal-Root Motion-Issues and Fixes

I could not find a relevant image for the Unreal Export option, but it would of existed in the drop down tab shown in the first image, much like the one that exist for Unity another Game engine.

Reasons this may have changed?

I have discovered through research that this option was buggy at best so speculation indicates they possibly removed it due to reports and issues they where having. However that is only Forum speculation.

What Issues have I discovered because of this?

However upon designing the Climb Blueprinting system mentioned previous I ran in to an Issue. I could not get the Actor to move up when running the Climb Animation I had that was created using the Program Mixamo. The Actor in question would not Climb the ledge as the Unreal Actor does in the Tutorial Videos ‘Both’. This lead me to my understanding of Root Motion as I tried to understand why my Animation differed to that of the Unreal Actors.

How did I set about fixing this issue?

I did a great deal of Research in this area and browsed many Forums, shown above. And also Unreals Documentation, again shown above. These aided my direction. I also looked at many Tutorials online that delved in to this problem specifically and showed ways in which one could correct it. Many alternate ways exist as do the Tutorials that explain them. In addition to this a Developer has created a Plugin directly for Unreal that will also fix the issue but without the same time restraints that govern the other methods available. Additionally through these Tutorials and my gained insights I created another method after gleaming ideas from Tutorials and after reading those Forum discussions.  That although it does allow you to use Mixamo it does not like the other methods allow you to use their Animations. However that method can still be achieved other ways. I have a list of Tutorials below that show those processes, I have tried many of them and other as-well as implemented them in an effort to understand them and why I am doing what it is I’m doing. They do work really well although many of them are very long and involve many programs and a good understanding of the process to fully implement and make the possible corrections needed to get them to not only work but work well. Another program I am yet to mention is a program called Maya and although my knowledge of this program is relatively new I have still used it on more than one occasion in the past, however with less finesse and knowledge than I have gained now. Using it previous was more robotic rather than autonomous.

Дополнительно:  Как скачать игру на android без root

What is Maya?

Maya is a 3D animation, modelling, simulation and rendering software. It provides an integrated, powerful toolset. Used commonly for animation and also environments, motion graphics, virtual reality and character creation. I use it often when doing Animations as I find it easier to use than doing the same in 3DS Max. A great deal of Tutorials are out there that show how to go about animating in Maya. I have also use the program in the past with an Unreal Blueprinting system, which has Tutorials that show how to rig and set up attaching equipment to Character Skeletons in Unreal, the Tutorials show the use of Maya and he has created his workflow around it, so to accomplish that element as Game-play within Unreal I needed to learn to use it on some level. This made using it now less daunting and I found it much easier to navigate the program ;’Maya’.

Tutorial 1-How to get Mixamo Root Motion in UE4

https://youtube.com/watch?v=9vJNiRPGAqk%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26start%3D487%26wmode%3Dtransparent

Tutorial 2-Add Root Bone to Mixamo Animations

https://youtube.com/watch?v=_QpDGNgg7IA%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26wmode%3Dtransparent

Tutorial 3-Re-target Mixamo Animations for use in UE4

https://youtube.com/watch?v=d4kH4qkxVBc%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26wmode%3Dtransparent

Unreal Plugin-Mixamo Re-targetting

The Plugin mentioned above is another way I could go about correcting the issue. Somebody out there has clearly seen the need for such a tool and created a really easy to use plugin to help manage the Assets available from Mixamo, the Rig and Animaions and port them in to Unreal and created a Root bone needed to allow Root Motion. He has also created a way in which to Take the Animation files from Mixamo and create a Root motion for those to allow them to function correctly in Unreal with that Root Motion applied. Like I say the Plugin really is a nifty bit of programming and does make that process of creating a Root bone much faster and still allows for the use of Mixamo Animations. note I will state as it seems prudent as he has that the Unreal Plugin is not affiliated with Mixamo. I will also state the Company name, UNAmedia. They are responsible for creating the Plugin. I have provided a Link below,

Unreal Mixamo Animation Re-targetting Plugin Link

Applying my own fix in Unreal

Fixing my own Character in Unreal for use in the Game design ‘Freedom’. As mentioned I tried most if not all of the methods above and again as stated they do work well they do take a while to implement however, once the process has become familiar it does speed up the process but having to implement it on every Animation is still time consuming regardless. I have some videos below that show how this progressed in Unreal. The first video demonstrates the error as I blogged in online to try and reach a resolve. The second video shows it fixed using ‘Tutorial 2’ from above and adding a Root bone to a Mixamo Rig. The third video merges alot of my learnt skills and from browsing Forums to allow me to merge the Animations from the Unreal Actor to my imported Skeleton Rigged using Mixamo with an added Root bone using Maya.

Video 1-Issue with Root Motion and Mixamo Imports

https://youtube.com/watch?v=542dQ4qRPTc%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26start%3D22%26wmode%3Dtransparent

https://youtube.com/watch?v=azjmDLFjlqc%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26start%3D4%26wmode%3Dtransparent

Video 3-Fixed Root issue by Re-targeting Unreal Skeleton to Mixamo Rig

https://youtube.com/watch?v=Lvngdh5IAps%3Fversion%3D3%26rel%3D1%26showsearch%3D0%26showinfo%3D1%26iv_load_policy%3D1%26fs%3D1%26hl%3Den%26autohide%3D2%26wmode%3Dtransparent

I my-self enjoy that aspect of Games Design, the Character still gets thought of but as I have not pushed this skill creating the Mesh from scratch and Rigging it would take me a considerable amount of time at present, to create a fully imagined Humanoid, I have had practice making abstract Actors or Characters from scratch. See image below:

Abstract Character Realisation in 3D and in Unreal

Paper Runner-Endless Runner Game

Unreal-Root Motion-Issues and Fixes

I much prefer being able to get down to the Mechanics of the Game and actually get Game-play elements working in conjunction with that Player, and I find using the Unreal Actor Template takes away from individuality of a current project regardless of its surroundings. Its clever placement so viewers of anything created by the use of the Unreal engine will nearly always feature the Unreal Template, in-fact it has become common place to see that Unreal Actor being used often in any Tutorial related to the Learning of the Unreal engine. Its a clever way of constantly validating its your engine by using that as its mascot and for those without the ability to replace that actor simply have no choice, plus he does look cool and he has become instantly recognisable now.

Summary and Conclusion

This concludes my tour in to Root Motion and how to not only implement it but do so in various ways. In addition I have learnt how to use Maya to a greater degree to aid the above development and fully implement a working Actor or Character of my choice in to the Unreal engine. This allowing me to further realise my individual projects pushing what I could do previously to a greater level by being able to implement other more complex Mechanics. I have a greater understanding of how Skeletons function and how to re-target Animations from one Skeleton to another and know the process involved and why it has to be done that way. I now understand what Root Motion is and how to achieve it and use it on an Actor or Rigged Skeleton, what is needed and how the Skeleton should look to allow the implementation of that Root Motion.  I can modify and rectify my Rigs to better improve how they look in engine when re-targeting Animations also. Many other skills have been gained from this exercise and it is a real testament to the phrase ‘perseverance pays off’.  Around three days was spent debugging and routing the cause of my issue not to mention trying to then correct that issue until finally I had reached a resolve and one that I was happy with. It still needs some work but I have since done further tweaking to the Skeleton and I have improved the look more, so it is still a work in progress and I am still learning the topic so my results are still trial and error if they wont always remain on some level trial and error. The process is complex and different Animations may appear different on each Skeleton and each Mesh based on Scale might deform differently on a re-target. So without some trial and error it would be impossible to know how something was going to look until you’ve just tried. There are things you can do to ensure its a smoother transition such as ensure a good amount of space between your Skeleton and your Mesh also ensure good placement. Then when Lining up your Re-target Source to your Skeleton try and be precise, this makes for a better re-target but that’s the only real control you can exhurt, I presume without a little more experience and a much greater understanding of Rigs and how to construct one fully.

Rootmotion has been mentioned in the previous articles. Its function is to make the animation and speed in the game perfectly match, and it has a very good performance effect. So, what is the principle of Rootmotion? How is it handled in UE? This article will help you analyze the principles in detail from the perspective of source code.

This article is suitable for Unreal/game developers with a certain amount of experience, but in order to take care of some newcomers (big guys) who are new to Unreal Engine, some basic concepts in the engine will also be explained.

RootMotion, root bone displacement, is a part of the combination of the movement group and the animation system, indicating that the overall movement of the character (including physics) is driven by animation.

Generally speaking, in most game applications, the player’s movement and animation are separated. The mobile system is only responsible for processing the player’s position and rotation. The animation system only does the corresponding animation performance. As long as the moving speed is appropriate, it can match the animation perfectly, that is to say, the position of the animation (ie the position of the Mesh) is Driven by the movement of the character (in UE4, the animation is driven by the position data of the capsule). One of the benefits of this is decoupling. There is no need for a close association between movement and animation, just focus on your content.

Дополнительно:  Ноутбук не включается с первого раза

However, some complex movements are difficult to simulate. For example, the official UE4 example: a person holding a hammer swings forward, the speed is relatively slow at first, and the speed will be very fast when the character cannot control it during the middle swing. When the hammer hits the ground, the speed becomes very slow again, and the character will stagger two steps.

Unreal-Root Motion-Issues and Fixes

In fact, no matter which method is used, it is difficult for us to find a general simulation solution that can handle all similar performances. So can we not simulate it? Just let the player animation play to a far position before moving the capsule? Nor, because in this case, if there is a wall in the middle, the character animation will pass through because there is no collision. The most ideal method is to give the art to an animation with displacement. The player’s position is completely handled by the animation. Different animations can have different movement performance. (There is also a way to process through curves, but the two are actually similar)

Unreal-Root Motion-Issues and Fixes

Therefore, we need RootMotion to cope with some complex animations, so that the character’s moving position can perfectly match the animation.

RootMotion operation and testing

After the concept is introduced, you may wish to test it. We can directly download the official ContentExample and open the Animation Level case 1.9 for testing. You can see that the green Character has turned on Rootmotion, and the capsule will always move with the animation, while the red Character has not turned on Rootmotion, so the capsule has not been displaced, and the animation has passed through without any collision.

Unreal-Root Motion-Issues and Fixes

Open its character blueprint and animation blueprint, and briefly look at the processing logic on the blueprint.

1. Set its MovementMode to Walk through the event, and then find its AnimInstance to convert to an animation blueprint and execute the predefined event-PlayRootMotionExample

Unreal-Root Motion-Issues and Fixes

2. PlayRootMotionExample is located in the animation blueprint, and it just performs a Montage playback. The Montage is synthesized by an animation with displacement. The animation is made by an animator in Maya and the exported .fbx file is imported into UE4. At the same time, you need to set Montage’s slot slot to FullBody and play the slot in the animation chart

Unreal-Root Motion-Issues and Fixes

Unreal-Root Motion-Issues and Fixes

3. Only importing animation resources is not enough, some configuration is needed. First of all, the root frame of the character should be at the origin without rotation. Second, you can see that there is a RootMotion option bar on the left side of the animation sequence (resource) blueprint, and you must check EnableRootmotion. Finally, there is a RootMotionMode under the AnimPreviewEditor on the right side of the animation blueprint. Click the drop-down box to select RootMotionFromMontagesOnly.

Unreal-Root Motion-Issues and Fixes

Unreal-Root Motion-Issues and Fixes

Unreal-Root Motion-Issues and Fixes

In addition, it is worth noting that the system supports network synchronization. When we turn on the multiplayer mode, the performance is still smooth, which is one of the key points of this article.

In theory, AnimSequence, Blendspace and AnimMontage can support network synchronization, but there will be several problems in the network environment, such as increasing the complexity of animation synchronization, affecting game performance, increasing the difficulty of prediction, and easily destroying animation performance, so generally we To turn off synchronization other than Montage, set Root Motion Mode to Root Motion From Montages Only. If Rootmotion of animation resource is turned on but RootMotionMode is not set, there will be a stuttering performance.

In fact, although Rootmotion supports Montages’ network synchronization, its prediction is much more difficult than ordinary mobile, and its performance is quite bad when the network environment is unstable. Therefore, in multiplayer games, Rootmotion should be used appropriately.

As for the specific details of synchronization and why this is the case, there will be a detailed analysis later.

Note: There are many instructional videos about Rootmotion on Youtube, here is a case of building from scratch and controlling according to player input

Understanding of RootMotion related concepts in UE4

The concept and use are explained in more detail in the previous section, and then we start to dive into the source code. First of all, consider the implementation of Rootmotion first. The basic idea is still quite simple, that is, the mobile component continuously reads the mobile Transform in the animation data every frame, and then applies it to the actual capsule. Of course, the specific implementation may be different from what we think, here is not to directly obtain and set the coordinates. Moreover, there are a lot of data and classes involved, and the logic is more complicated. We need to understand the implementation principles of the animation system and mobile components at the same time.

Unreal-Root Motion-Issues and Fixes

Here are the related concepts involved:

The ability to move in UE4 is encapsulated in a component (component design, most functions are encapsulated in different components), separated from the real player character, different characters can configure different components and set their own Parameters to achieve different moving effects

About mobile components, you can go to my last article to check.

Rootmotion stand-alone execution process and principle

Animation data initialization:

1. When the Character bound to the animation blueprint enters the scene, it has already started various animation data-related initializations (UAnimInstance::Initialize-Animation), and then continuously updated the logic in the animation blueprint through UpdateAnimation, while giving part of the logic to FAnimInstanceProxy processing. To

Unreal-Root Motion-Issues and Fixes

2. Generally, the player manually triggers the playback of Montage, finds the corresponding AnimInstance through USkeletalMeshComponent and executes Montage_Play of UAnimInstance

3. Create a FAnimMontageInstance and perform related initialization to start the real montage playback

4. Determine whether the montage has Rootmontion, if yes, assign it to RootMotionMontageInstance for subsequent judgment

Unreal-Root Motion-Issues and Fixes

5. After Montage is initialized, it will participate in the calculation in the AnimInstance::UpdateAnimation executed in each subsequent frame. Under normal circumstances, as long as our animation update method does not select OnlyTickPoseWhenRendered,Montage will participate in the update, and the update logic is in UAnimInstance::UpdateMontage

EVisibilityBasedAnimTickOption::OnlyTickPoseWhenRendered (there are four types)

Unreal-Root Motion-Issues and Fixes

Mobile component PerformMovement:

Unreal-Root Motion-Issues and Fixes

2. Make another judgment to make sure whether to update the animation system. If the above condition b is established again, start to prepare, that is, update the animation to execute TickCharacterPose (TickPose is called every frame in the Mesh component by default, because the Tick timing is different from the Mesh component, it needs to be executed once) , Which will call UpdateAnimation of UAnimInstance to update the animation, and in the Advance functionUpdate the current Montage displacement information to the AnimInstance member variable ExtractedRootmotion.

Unreal-Root Motion-Issues and Fixes

Unreal-Root Motion-Issues and Fixes

Then there may be a question here, how exactly is the Transform data in Montage animation parsed out?

The answer is in the function UAnimMontage::ExtractRootMotion-FromTrackRange. We need to pass in the playback position of this frame of animation before playing and the position where Montage is currently executed as parameters. Montage will get all AnimSequence fragments from the current track SlotTrack (that is, FAnimSegment in the stack diagram below), and judge Which AnimSequence fragment currently Montage is in and parse out the corresponding FRootMotion-ExtractionStep (this object actually just encapsulates the corresponding AnimSequence and the starting position of this frame).

Unreal-Root Motion-Issues and Fixes

Finally, the DeltaTransform of RootMotion is calculated according to the corresponding AnimSequence and the starting position of the current playback. It should be noted that what is obtained here is a displacement rather than a position. (Get through UAnimSequence::Get-BoneTransform)

3. If we have now extracted Montage information into ExtractedRootmotion, how can the animation data such as AnimSequence and BlendSpace in the animation blueprint participate in the calculation together? In the concept understanding, we mentioned the core class FAnimInstanceProxy optimized for multi-threading. By default, most of the update logic in the animation blueprint is placed in FAnimInstanceProxy. Regardless of whether it is multi-threaded or not, we need to process related logic through FAnimInstanceProxy. And here extract the Rootmotion data of all animation resources into ExtractedRootMotion according to the weight.

If the current RootMotionMode is RootMotion-FromEverything, then we will immediately update TickAssetPlayer-Instances when the main thread is Tick, so that we can get the Rootmotion information of each frame in time.

Unreal-Root Motion-Issues and Fixes

Main thread update

If RootMotionMode is another mode, TickAssetPlayerInstances will be placed in other threads for execution.

Unreal-Root Motion-Issues and Fixes

Update from other threads

Similarly,If the currentRootMotionMode is RootMotionFrom-Everything. After the Proxy is updated, we need to extract all the resource data involved in the calculation into ExtractedRootMotion according to the weight in time.

Unreal-Root Motion-Issues and Fixes

1. After TickPose, if the character is in the IsPlayingRootMotion state, it will execute ConsumeRootMotion to consume the ExtractedRootmotion generated by Animinstance in the previous stage, in fact, copy the ExtractedRootmotion data obtained previously to the new variable RootMotion and clear the ExtractedRootmotion

2. The new Rootmotion data will be scaled and adjusted according to ACharacter’s AnimRootMotionTranslationScale, and its related data will be copied to the member variable RootMotionParams of the mobile component.

Дополнительно:  Почему ноутбук издаёт писк во время работы или при выключении -

Unreal-Root Motion-Issues and Fixes

3. Convert RootMotionParams from local to world coordinates

4. Perform mobile simulation, that is, apply the previously obtained Transform to the mobile component. Here, a speed AnimRootMotionVelocity will be calculated based on the current DeltaTransform and deltaTime of Rootmotion for simulation. The specific logic is in StartNewPhysics (including PhysWalking, Flying, etc.). Different movement states here will judge Rootmotion and then process speed. Note: This step will not update its Rotation

Unreal-Root Motion-Issues and Fixes

5. At the end of the simulation, read the Transform of RootMotionParams to update the Rotation

6. Clear the data in RootMotionParams, a member of the mobile component

One point needs to be emphasized, Rootmotion is gradually accumulated, which means that every time we get the Transform is the displacement of its movement within the current Tick time, rather than referring to a specific coordinate. The Accumulate function means to assign the currently passed DeltaTransform to the data we currently record.

In addition, the above also mentioned a configuration AnimRootMotion-TranslationScale on Character. Since the length of the animation produced by the animator is fixed, and the demand in the game changes, can we ensure that the distance the character moves each time is the same as the animator designed it? No, for example, if the player climbs over an obstacle, the size of the obstacle cannot be strictly the same, so we need a parameter to adjust the adaptation. This parameter is AnimRootMotion-TranslationScale, which can be set by the function SetAnimRootMotion-TranslationScale.

Simulated client synchronization

(When the server does not receive the synchronization data, the execution logic of the server is roughly the same, except that it is triggered in SimulateTick)

1. The server locally triggers the execution of MontagePlay and assigns it to RootMotionMontageInstance

2. After the Simulated client triggers MontagePlay on the server, MontagePlay is then triggered through the attribute callback

note:The second step here needs to be handled by the developer. Generally speaking, the server should modify a certain attribute after execution, and then the callback function of this attribute triggers the client to execute MontagePlay. There is a short network delay in the execution of both.

1. The mobile component executes Tick, UCharacterMovement-Component::SimulatedTick

Unreal-Root Motion-Issues and Fixes

3. TickCharacterPose, parse out the DeltaTransform from the current position of the animation, and extract it with ExtractedRootMotion on AnimInstance. For specific details, please refer to the stand-alone process above

Unreal-Root Motion-Issues and Fixes

5. Call SimulateRootMotion to convert to world coordinates, calculate the Rootmotion speed and start to call StartNewPhysics for simulation. Unlike the stand-alone version, the simulation process is handled in the function SimulateRootMotion. There is a point to pay special attention to here. Since the Simulated client synchronizes through the network, it may be stuck due to network fluctuations, so this function will only update the position of the capsule first (bEnableScopedMovementUpdates is true), and does not update the Mesh position. Mesh needs to be smoothed by local Tick, and its logic will be further described below.

6. After the simulation, if Rotation is not the default value FQuat::Identity, it will be modified by MoveUpdatedComponent to clear the temporarily extracted RootMotionParams related data

The above mentioned is the process of client simulation, but since it is synchronized, of course the client and the server are required to interact

note:The player has a member attribute FRepRootMotionMontage RepRootMotion records the running information of the Rootmotion of the server in each frame, including the coordinates, rotation, Montage, speed, execution position of the current frame, etc.This property is synchronized (and only synchronized when Rootmotion is played). When the server is playing Rootmotion, each frame will be processed by ACharacter’s PreReplication and sent to the Simulated client.The RootMotionRepMoves array stores all Rootmotion data sent by the server. The RepRootMotion mentioned earlier will be extracted from the client’s callback function and added to the RootMotionRepMoves array.

Unreal-Root Motion-Issues and Fixes

7. After the client simulates the movement, it will start to verify according to the Rootmotion information of the server, and execute the function ACharacter::SimulatedRootMotionPositionFixup. This will first determine whether the client wants to use the data in the RootMotionRepMoves array (condition: less than 0.5 seconds, in the same Section fragment, acyclic Montage, the server is behind the client and the position closest to the client)

Unreal-Root Motion-Issues and Fixes

8. If the data RepRootMotion that meets the conditions is found, it will first modify the coordinates and rotation of the local character according to the data passed by the server through ACharacter::RestoreReplicatedMove. Subsequently, perform ExtractRootMotionFromTrackRange to implement the rollback of Rootmotion according to the location of the current server and the location of the client. This is just to get a rollback result.

9. Finally, calculate an interval time according to deltaposition and playrate, and then perform a local simulation SimulateRootMotion according to the rollback result LocalRootMotion.

10. Call SmoothCorrection for smoothing after simulation. As mentioned earlier, SimulateRootMotion will only update the position of the capsule and not the position of the Mesh, just for smoothing here. The smooth logic is probably that the client records a ClientData data to record the current Mesh offset and the server’s time stamp. In the Tick of each subsequent frame, the Offset offset is constantly updated to gradually become 0. When the offset is At 0, the Mesh completely overlaps with the capsule body to complete the smoothing. The specific logic can refer to my last article.

Autonomous client synchronization process

1. The client executes Montage playback locally, and informs the server to play via RPC

2. The server receives the RPC to trigger MontagePlay and assign it to RootMotionMontageInstance

(Of course, a similar way to the simulated client can also be used here, playing on the server first, and triggering the Autonomous client to play through the attribute callback)

(Due to the logic repetition, some steps will be simplified here)

1. Similar to the simulated client above to execute TickComponent, but the function triggered here is not SimulatedTick but ReplicateMoveToServer. Then execute PerformMovement to extract Rootmotion information (execute TickCharacterPose)

Unreal-Root Motion-Issues and Fixes

2. Calculate the speed according to deltatime and DeltaTransform, call StartNewPhysics to simulate Rootmotion movement

3. Update Rotation, clear the temporarily extracted RootMotionParams related data. Store the relevant data of this move in FSavedMove_Character, record this move and store it in the SavedMoves array (for rollback, etc.)

4. Execute CallServerMove, send the locally calculated data to the server, and call the RPC function ServerMove

(If you encounter a situation where PendingMove performs an optimized move, you need to perform a special RPC)

1. The server executes the MoveAutonomous re-simulation calculation based on the client information, and judges whether the client’s movement is legal based on the result.

2. Subsequently, when the server performs the synchronization of ServerReplicateActors, it sends ACK or Adjust. If the server is playing Montage at this time and finds that there is a problem with the client data, it will execute ClientAdjustRootMotionSourcePosition to correct it. Otherwise, normal correction logic will be executed.

Unreal-Root Motion-Issues and Fixes

3. If the client receives the AdjustRootMotion message, it will first update the data of the mobile component according to the coordinates and other information passed by the server (execute ClientAdjustPosition), and then directly set the position of the local Montage animation according to the Montage Position passed by the server.

The synchronization process of the Autonomous client is actually very complicated. It is recommended to read the official document or the article I mentioned earlier to get a general understanding.

to sum up

As we mentioned earlier, the fundamental reason for this is that the synchronization of the animation system (or animation state machine) is complicated and difficult. The current animation synchronization method commonly used by Unreal Engine is that the client and the server maintain a state machine and several Synchronize the attribute values, and then synchronize the animation through the judgment of these attributes. The animation state machine here is not synchronized. Once the animation system becomes complex, the switching and transitions between various states will become extremely complicated. Due to the instability of the network environment, the synchronization of the state machine requires very strict design and processing (of course, this is not to say that it cannot be done). It is best to synchronize the status of each frame with the trigger event, and then do more additional verification work. Therefore, we have seen that in addition to the basic state of many game animations, many other animations are synchronized through Montage. Montage can be interrupted and independent, so it is relatively easy to synchronize.

In addition, because Rootmotion is essentially a solution used to improve the performance effect, stand-alone simulation is more difficult, and it is even more difficult for network synchronization that requires prediction, or unless it is a regular linear motion Rootmotion, other irregularities Movement is almost unpredictable. And if we do not predict, it will be difficult for us to deal with network jitter, once the entire network performance is no longer smooth.Therefore, in the case of a bad network environment, the performance of complex Rootmotion is quite poor.Finally, in terms of performance, reducing data synchronization and verification can reduce the pressure on the server’s CPU and memory, so the use of Rootmotion in online games should be carefully considered.

Welcome to join the game development learning exchange group (875867499)

Оцените статью
Master Hi-technology
Добавить комментарий