# C++ Replicating Animations

**URL:** <https://forums.unrealengine.com/t/c-replicating-animations/353112>\
**Category:** Character & Animation\
**Tags:** Replication, UE4-10, unreal-engine, CPP, question\
**Created:** [April 6, 2016, 5:39am UTC](https://forums.unrealengine.com/t/c-replicating-animations/353112 "2016-04-06T05:39:01Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![ryanjon2040](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ryanjon2040/32/906587_2.png) [@ryanjon2040](https://forums.unrealengine.com/u/ryanjon2040)\
**Post date:** [April 6, 2016, 5:53am UTC](https://forums.unrealengine.com/t/c-replicating-animations/353112/2 "2016-04-06T05:53:08Z")

</div>

I didnt test this code but can you please try this and report back?

```
// ACharacter.h
 
 public:
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay)
 class UAnimMontage* FireAnimation;
 
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = WeaponUsage)
 class USoundBase* FireSound;
 
 UFUNCTION(NetMulticast, Reliable)
 void MulticastSetFiring();
 
 UFUNCTION(Server, Reliable, WithValidation)
 void ServerSetFiring();
 
 UFUNCTION()
 void SetFiring();
 
 protected:
 void OnFire();
 
 // ACharacter.cpp
 
 void ACharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
 {
   Super::GetLifetimeReplicatedProps(OutLifetimeProps);
 }
 
 void ACharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
 {
   // set up gameplay key bindings
   check(InputComponent);
 
   InputComponent->BindAction("Fire", IE_Pressed, this, &ACharacter::OnFire);
 }
 
 // WIP - Only Server can see animations of clients.
 void ACharacter::MulticastSetFiring_Implementation()
 {
    SetFiring();
 }
 
 void ACharacter::ServerSetFiring_Implementation()
 {
   MulticastSetFiring();
 }
 
 bool ACharacter::ServerSetFiring_Validate()
 {
   return true;
 }
 
 void ACharacter::OnFire()
 {
   if (HasAuthority())
   {
        SetFiring();
   }
   else
   {
        ServerSetFiring();
   }
 }
 
 void ACharacter::SetFiring()
 {
    // try and play the sound if specified
   if (FireSound != NULL)
   {
     UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
   }
 
   // try and play a firing animation if specified
   if (FireAnimation != NULL)
   {
     // Get the animation object for the arms mesh
     UAnimInstance* AnimInstance = Mesh1P->GetAnimInstance();
     if (AnimInstance != NULL)
     {
       AnimInstance->Montage_Play(FireAnimation, 1.f);
     }
   }
 }
```

---

_[View the full topic](https://forums.unrealengine.com/t/c-replicating-animations/353112)._
