I have the following Blueprint in my character:
As commented one part of it works perfectly the other fails silently without any kind of hint or a message.
The C++ function is very simple (I’ll paste just the .cpp as the .h is irrelevant IMO)
#include "MyBlueprintFunctionLibrary.h"
#include "GameFramework/RootMotionSource.h"
#include "GameFramework/CharacterMovementComponent.h"
void UMyBlueprintFunctionLibrary::RootMotionConstantForce(AActor* Target, FVector Displacement, float Duration)
{
if (Target)
{
auto MovementComponent = Cast<UCharacterMovementComponent>(Target->GetComponentByClass(UCharacterMovementComponent::StaticClass()));
if (MovementComponent)
{
TSharedPtr<FRootMotionSource_ConstantForce> ConstantForce = MakeShared<FRootMotionSource_ConstantForce>();
ConstantForce->InstanceName = FName("ApplyRootMotionConstantForce");
ConstantForce->AccumulateMode = ERootMotionAccumulateMode::Override;
ConstantForce->Priority = 5;
ConstantForce->Force = (Duration>.0f)? Displacement/Duration : Displacement;
ConstantForce->Duration = Duration;
ConstantForce->StrengthOverTime = nullptr;
ConstantForce->FinishVelocityParams.Mode = ERootMotionFinishVelocityMode::SetVelocity;
ConstantForce->FinishVelocityParams.SetVelocity = FVector::ZeroVector;
ConstantForce->FinishVelocityParams.ClampVelocity = 0.0f;
if(GEngine) GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Red, MovementComponent->GetReadableName());
uint16 RootMotionSourceID = MovementComponent->ApplyRootMotionSource(ConstantForce);
}
}
}
I can confirm that both graphs reach line 26 with a valid movement components. I can also confirm that both of them hit CharacterMovementComponent(11573).
However, I have no idea how Root Motion Source are accumulated or how and why they might be discarded without any kind of notice.
If anyone has any insight, please let me know.