I am still confused if there should be a ROLE_Authority
check when calling SetOwner()
in a multiplayer game. When would the client need to call SetOwner()
instead of the server and vice versa? When should it be called by BOTH the client and the server?
In ShooterGame it’s called by both the client and the server.
Called by Server:
-
AShooterCharacter::AddWeapon()
has aROLE_Authority
check before callingAShooterWeapon::OnEnterInventory()
which callsAShooterWeapon::SetOwningPawn()
which then callsSetOwner()
Called by Client:
- When
AShooterWeapon::MyPawn
is replicated,AShooterWeapon::OnRep_MyPawn()
callsAShooterWeapon::OnEnterInventory()
which callsAShooterWeapon::SetOwningPawn()
which then callsSetOwner()
However unlike OnEnterInventory()
, OnLeaveInventory()
has an explicit ROLE_Authority
check before calling SetOwningPawn()
. So I am confused about where SetOwner()
should be called in a multiplayer game (on client or server or both).
Could anyone explain the rationale behind calling SetOwner()
on server-only, client-only, or both in a multiplayer game?