Size: 600
Comment:
|
Size: 1428
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 12: | Line 12: |
{{{#!highlight C++ // ThirdPersonMPCharacter.h /** The player's current health. When reduced to 0, they are considered dead.*/ UPROPERTY(ReplicatedUsing=OnRep_CurrentHealth) float CurrentHealth; /** RepNotify for changes made to current health.*/ UFUNCTION() void OnRep_CurrentHealth(); /** Property replication */ void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override; }}} {{{#!highlight C++ ////////////////////////////////////////////////////////////////////////// // Replicated Properties void AThirdPersonMPCharacter::GetLifetimeReplicatedProps(TArray <FLifetimeProperty> & OutLifetimeProps) const { Super::GetLifetimeReplicatedProps(OutLifetimeProps); //Replicate current health. DOREPLIFETIME(AThirdPersonMPCharacter, CurrentHealth); } }}} |
How to add replication to a base Actor #1
How to take advantage of Movement Components in a network game #2
How to add replication to variables #3
How to use RepNotifies when a variable changes #4
How to use Remote Procedure Calls (RPCs) in C++ #5
How to check an Actor's Network Role in order to filter calls that are performed within a function #6
How to add replication to a base Actor
1 // ThirdPersonMPCharacter.h
2 /** The player's current health. When reduced to 0, they are considered dead.*/
3 UPROPERTY(ReplicatedUsing=OnRep_CurrentHealth)
4 float CurrentHealth;
5
6 /** RepNotify for changes made to current health.*/
7 UFUNCTION()
8 void OnRep_CurrentHealth();
9
10 /** Property replication */
11 void GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const override;
1 //////////////////////////////////////////////////////////////////////////
2 // Replicated Properties
3
4 void AThirdPersonMPCharacter::GetLifetimeReplicatedProps(TArray <FLifetimeProperty> & OutLifetimeProps) const
5 {
6 Super::GetLifetimeReplicatedProps(OutLifetimeProps);
7
8 //Replicate current health.
9 DOREPLIFETIME(AThirdPersonMPCharacter, CurrentHealth);
10 }