Disable Root Motion at Runtime

I’ve noticed that whenever root motion happens, it will completely override any other movement in the x and y direction. For instance, I have a bit of knock-back attached to my character’s attacks, I do this by temporarily lowering the friction on the hit character and launching them away.

This works great, however if the character makes an attack (or plays any root motion animation) while being knocked back (even if they are in midair) they will lose all their momentum immediately and follow the root motion animation. Even if I apply constant velocity every tick, root motion makes it as if it isn’t happening.

The best solution I can think of is turning root motion off while they are being knocked back, however there doesn’t seem to be a way to access the root motion type in the animation blueprint. Does anyone have any way to turn it off, or another solution to allow root motion and physics to interact?

Well I found a way around this problem. All I did was create my own AnimInstance class in C++ and exposed the RootMotionMode variable to be edited through a function.

1 Like

Sorry to necromance this, but could you explain your solution a bit more in depth? How do you create your owb AnimInstance and expose the RootMotionMode to Blueprint?

Could you make a tutorial how you did that ? I got problem with that but I can’t C++. Could you help ?

Create a new C++ class (right-click within the content browser). Make sure “Show All Classes” is checked. Choose Parent Class: “AnimInstance”

And below the “public:” line in your newly created .cpp file, add the following method (not tested, but this should work)

    UFUNCTION(BlueprintCallable)
    void EnableRootMotionMode(bool bEnable)
    {
        if (bEnable)
        {
            this->RootMotionMode = ERootMotionMode::RootMotionFromMontagesOnly;
        }
        else
        {
            this->RootMotionMode = ERootMotionMode::IgnoreRootMotion
        }
    }

i hope this helps, cheers!

1 Like