[UE4][Animation]Root Motion Notes
Keywords: UE4, Animation, RootMotion, Root Motion, Montage

蓝图设置方式
Root Motion 设置步骤:
- 先在 AnimSequence 的
Asset Detail面板中勾选EnableRootMotion和Force Root Lock。 - 然后基于该 AnimSequence 新建一个 AnimMontage。
- 然后再在 AnimationBluerpint 中设置
Root Motion Mode为Root Motion From Montages Only(Class Defaults 面板下,不是Class Settings)。
如果你没有使用UE4的服务器、或者使用了UE4服务器但是没有对动画启用Replication(服务端通过 NetMulticast 播放动画),设置为Root Motion from Enerything没有问题,如果使用了UE4的Replication,且这些动画文件(AnimSequence, Blendspace, AnimMontage, etc.)勾选了EnableRootMotion,那么 Root Motion 也会被同步,影响性能。所以官方文档上的建议是使用默认设置,即:Root Motion Mode设置为Root Motion From Montages Only,只对Montage的Root Motion进行Replication。
Root Motion
https://docs.unrealengine.com/en-US/Engine/Animation/RootMotion
C++设置方式
-
v4.5之前的方式: UAnimMontage 的两个属性
bEnableRootMotionTranslation、bEnableRootMotionRotation,任意一个设置为 true 即可。
AnimMontage.cpp 引擎代码:bool bRootMotionEnabled = bEnableRootMotionTranslation || bEnableRootMotionRotation; if (bRootMotionEnabled) { for (FSlotAnimationTrack& Slot : SlotAnimTracks) { for (FAnimSegment& Segment : Slot.AnimTrack.AnimSegments) { if (Segment.AnimReference) { Segment.AnimReference->EnableRootMotionSettingFromMontage(true, RootMotionRootLock); } } } } -
v4.5的新方式:
UAnimSequence::bEnableRootMotion = true;
Blend Animation时动画卡顿
播放Montage时,如果角色可能正在发生位移,且在有Dedicated Server情况下,那么对应的AnimSequence需要禁用RootMotion,否则角色移动过程中,如果正在混合Montage,会导致角色动画卡顿。或者将Root Motion Mode设置为everything(但这样会增加Dedicated Server开销)。
Reference
《Exploring in UE4》UE4 RootMotion详解【原理分析】
https://zhuanlan.zhihu.com/p/74554876
UE4 adding root motion animations from mixamo
https://www.youtube.com/watch?v=50Ax7tGg7hA
什么是最困难的?与生活讲和。 ──米奇·阿尔博姆(MitchAlbom)《相约星期二》