In Shooter Game, AShooterWeapon::MyPawn
is replicated using the following:
Header:
UPROPERTY(Transient, ReplicatedUsing=OnRep_MyPawn)
class AShooterCharacter* MyPawn;
UFUNCTION()
void OnRep_MyPawn();
cpp:
void AShooterWeapon::OnRep_MyPawn()
{
if (MyPawn)
{
OnEnterInventory(MyPawn);
}
else
{
OnLeaveInventory();
}
}
void AShooterWeapon::OnEnterInventory(AShooterCharacter* NewOwner)
{
SetOwningPawn(NewOwner);
}
void AShooterWeapon::SetOwningPawn(AShooterCharacter* NewOwner)
{
if (MyPawn != NewOwner)
{
SetInstigator(NewOwner);
MyPawn = NewOwner;
// net owner for RPC calls
SetOwner(NewOwner);
}
}
I would like to ask for an explanation of the logic of calling OnEnterInventory
in OnRep_MyPawn
. The RepNotify function is only called when MyPawn
has already been changed, right? So my understanding is that OnEnterInventory
will call SetOwningPawn
which will check if (MyPawn != NewOwner)
which will always evaluate to false
because MyPawn
has already been replicated, and hence nothing will be done.
What is the point of doing this? Or is my understanding wrong?