Calling SetOwner() on client and server

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 a ROLE_Authority check before calling AShooterWeapon::OnEnterInventory() which calls AShooterWeapon::SetOwningPawn() which then calls SetOwner()

Called by Client:

  • When AShooterWeapon::MyPawn is replicated, AShooterWeapon::OnRep_MyPawn() calls AShooterWeapon::OnEnterInventory() which calls AShooterWeapon::SetOwningPawn() which then calls SetOwner()

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?

1 Like