i am trying to apply rotation to a character using the uint16 function ApplyRootMotionSource" in the UCharacterMovementComponent with gameplay tasks, and the editor crashes when it tries to apply it.
i am still new to c++ programing and ue4 so i took “AbilityTask_ApplyRootMotionConstantForce” Code as an example in making my code. variables and functions declaration are almost the same
function code for applying rootmotion:
void UWOSAbilityTask_ApplyRootMotionRotation::InitAndApply()
{
if (AbilitySystemComponent->AbilityActorInfo->MovementComponent.IsValid())
{
MovementComponent = Cast<UCharacterMovementComponent>(AbilitySystemComponent->AbilityActorInfo->MovementComponent.Get());
if (MovementComponent)
{
ForceName = ForceName.IsNone() ? FName("AbilityTaskApplyRotation") : ForceName;
FRootMotionSource* RootMotionSource = new FRootMotionSource();
RootMotionSource->Duration = Duration;
RootMotionSource->InstanceName = ForceName;
RootMotionSource->Priority = 5;
RootMotionSource->AccumulateMode = ERootMotionAccumulateMode::Override;
RootMotionSource->FinishVelocityParams.Mode = ERootMotionFinishVelocityMode::MaintainLastRootMotionVelocity;
RootMotionSource->RootMotionParams.Accumulate(FTransform(DesiredRotation, FVector(1.f, 1.f, 1.f)));
RootMotionSourceId = MovementComponent->ApplyRootMotionSource(RootMotionSource);
if (Ability)
{
Ability->SetMovementSyncPoint(ForceName);
}
}
}
}