I've just completed the Networking Quickstart tutorial, where the project is called ThirdPersonMP: https://docs.unrealengine.com/en-US/...art/index.html
Part of the code is to show a debug message on the screen when health is lost (due to being hit by projectile), and as I understand it this text should only be visible for the player being shot at.
Also, this is explicitly mentioned in the guide:
However, when I run it locally, the text is shown on both screens. If I increase from 2 to 3 players the message is shown on all screens.
My understanding is that the way to differentiate players here is the IsLocallyControlled() call:
Is this the expected behaviour, or does this mean that I have done a mistake somewhere along the tutorial? Or is it because when I run in in the editor all players are run locally "for me"?
My only deviation from the tutorial (AFAIK) is that I include void HandleFire_Implementation(); in my ThirdPersonMPCharacter.h-file becuase otherwise it wouldn't compile:
Part of the code is to show a debug message on the screen when health is lost (due to being hit by projectile), and as I understand it this text should only be visible for the player being shot at.
Also, this is explicitly mentioned in the guide:
When one player is hit by the custom projectile, the explosion particle should appear for both players, and the player taking the hit will receive a "hit" message telling them how much damage they took and their current health, while all other players in the session should not see anything.
My understanding is that the way to differentiate players here is the IsLocallyControlled() call:
Code:
void AThirdPersonMPCharacter::OnHealthUpdate() { // Client-specific functionality if (IsLocallyControlled()) { FString healthMessage = FString::Printf(TEXT("You now have %f health remaining."), CurrentHealth); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, healthMessage); if (CurrentHealth <= 0) { FString deathMessage = FString::Printf(TEXT("You have been killed.")); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, deathMessage); } } // Server-specific functionality if (Role == ROLE_Authority) { FString healthMessage = FString::Printf(TEXT("%s now has %f health remaining."), *GetFName().ToString(), CurrentHealth); GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, healthMessage); } //Functions that occur on all machines. /* Any special functionality that should occur as a result of damage or death should be placed here. */ }
My only deviation from the tutorial (AFAIK) is that I include void HandleFire_Implementation(); in my ThirdPersonMPCharacter.h-file becuase otherwise it wouldn't compile:
Code:
// in ThirdPersonMPCharacter.h /** Server function for spawning projectiles.*/ UFUNCTION(Server, Reliable) void HandleFire(); void HandleFire_Implementation();
Comment