I got it all done. Thanks for the help. Posting the completed code here if anybody in the future needs it. I created the reference to CharacterMovementComponent and it works great. Just incase the reference at begin play fails the else statement will use MoveComp. With the AnimInstance->Montage_IsPlaying this disables the player from spamming the button and restarting the animation.
header.h
protected:
// Called when Main Attack button pressed IE: LMB
void MainAttack();
// Used to set walking again when disabled before using anim play montage
UFUNCTION()
void EnableWalk();
private:
// Timer handle for disable character movement
FTimerHandle TimerMovementWalking;
// Save pointer reference for CharacterMovementComponent
UCharacterMovementComponent* MoveCompRef = nullptr;
file.cpp
// Called when the game starts or when spawned
void ARPGCharacter::BeginPlay()
{
Super::BeginPlay();
MoveCompRef = GetCharacterMovement();
}
void ARPGCharacter::MainAttack()
{
UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();
if (AnimInstance && MainAttackMontage)
{
// Check to see if the montage is already playing
if (!AnimInstance->Montage_IsPlaying(MainAttackMontage))
{
// Check reference to CharacterMovementComponent and disable movement.
if (MoveCompRef)
{
MoveCompRef->DisableMovement();
}
else
{
UCharacterMovementComponent* MoveComp = GetCharacterMovement();
MoveComp->DisableMovement();
}
float EnableWalkTime = AnimInstance->Montage_Play(MainAttackMontage);
GetWorldTimerManager().SetTimer(TimerMovementWalking, this, &ARPGCharacter::EnableWalk, EnableWalkTime);
}
}
}
void ARPGCharacter::EnableWalk()
{
// Check reference to CharactermovementComponent and set character movement to walking
if (MoveCompRef)
{
MoveCompRef->SetMovementMode(MOVE_Walking);
}
else
{
UCharacterMovementComponent* MoveComp = GetCharacterMovement();
MoveComp->SetMovementMode(MOVE_Walking);
}
}