Does anyone knows why ApplyRootMotionSource() doesn't work on non-controlled characters?

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.

Ok… I got it somewhat. I’m writing this in hope of saving someone two days of debugging. (drum roll please) If ApplyRootMotionSource() does not work…

Check if the Controller is valid…

Both the caller and the other Actor were set to “Auto Possess Player 0” because they were cloned. However, at the start of the game only one is possessed and the other remains with invalid Controller. Yes the Movement Component is valid and active however missing a Controller somehow prevents it from functioning correctly. When and how this is checked and why is it relevant in the case of root motion is still unclear to me.

Why there is no warning is beyond me.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.