EDIT: Updated with new infos. Fixed the error, still no animation playing from c++
Hey there,
i have some trouble playing my weapon animations in C++.
I have the Prototype Weapons that come along with a Fire and Reload Animation and i wanted to test my Shooting Methods.
My current system will get the LeftMouseButton press in the PlayerController, check if there is a valid weapon in the weapon
slot and call its ShootWeapon() function:
/// Weapon Functions ///
void ASmallCoopTDPlayerController::ShootWeapon()
{
ASmallCoopTDCharacter* MyCharacter = Cast<ASmallCoopTDCharacter>(GetPawn());
if (MyCharacter)
{
class ABaseWeaponClass* MyWeapon = Cast<ABaseWeaponClass>(MyCharacter->GetCurrentWeapon());
if (MyWeapon)
{
MyWeapon->ShootWeapon();
}
}
}
Now the WeaponClass has 2 Variables to save and set my Animation in the ChildBP (i create the final weapons in as BP, so that
i can edit them easier):
protected:
/// Weapon Animations ///
UPROPERTY(Replicated, BlueprintReadWrite, EditDefaultsOnly, Category = "Weapon Animtions")
UAnimMontage* ReloadAnimation;
UPROPERTY(Replicated, BlueprintReadWrite, EditDefaultsOnly, Category = "Weapon Animtions")
UAnimMontage* ShootAnimation;
So these are set in my BP to the specific Animation Montage.
Now in the ShootWeapon() function, i do the following:
/// Client Functions ///
void ABaseWeaponClass::ShootWeapon()
{
if (Role < ROLE_Authority)
{
Server_ShootWeapon();
}
}
/// Server Functions ///
void ABaseWeaponClass::Server_ShootWeapon_Implementation()
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Shooting Weapon!"));
GetWeaponMesh()->GetAnimInstance()->Montage_Play(ShootAnimation);
}
bool ABaseWeaponClass::Server_ShootWeapon_Validate()
{
return true;
}
The OnScreenMessage is displayed but the Montag Play does nothing.
When i call the same thing withing a blueprint (PlayMontage etc) it is working.
But the same in C++ doesnât work somehow.
If you need more information or more code, please tell me!
(: Thanks in advance
/// EDIT 1 ///
Ok, i debugged it alot now and it seems like iâm missing some replication here.
If i call this through a normal client side function, it is shooting correctly (not replicated, only visible client side).
If i call it through the server function, it seems like it is playing (Montag_IsPlaying returns true),
but i canât see the animation ingame.