ActorGun is spawned dynamicly.
By SetOwningPawn(..) the MyPawn is set as owner.
On every shot I call method (on Server), which changes property of ActorGun, named LastShotInfo.
This prop. is declared such way:
LastShotInfo inside AActorGun::GetLifetimeReplicatedProps(..) is added without any conditions:
DOREPLIFETIME(AActorGun, LastShotInfo);
So, I expect, method OnRep_LastShotInfo(..) will be called on every relevant (e.g. located <= some distance) client every time the LastShotInfo property is changed.
This method I’ve defined such way:
void AActorGun::OnRep_LastShotInfo()
{
PlayShot(); //! plays cosmetic
if (Role == ROLE_AutonomousProxy)
{
OnShot.Broadcast(); //! signal to current client UI to redraw some effects.
}
}
I want the OnShot.Broadcast() to be called only on owning client to redraw UI only for player, who have did this shot
BUT! this broadcast is never called =(
Every time, I fall inside OnRep_LastShotInfo(..), the Role is == ROLE_SimulatedProxy.
Why is it so?
How can I separate unique logic for owner client only inside the OnRep_LastShotInfo() method?
void AActorGun::OnRep_LastShotInfo()
{
PlayShot(); //! plays cosmetic
if (IsLocallyControlled())
{
OnShot.Broadcast(); //! signal to current client UI to redraw some effects.
}
}
An instance of the running game (a game client) will only have Role == ROLE_Authority (which is equivalent to HasAuthority()) on an Actor when it was locally spawned. A remote client possessing a replicated Actor that was spawned by the server does not give the remote client authority. It merely indicates that it is “controlled”, hence the IsLocallyControlled() call, which eventually reaches calls this code on the player controller: Controller->IsLocalController();
Hmm, it seems there is some weird flaw in the UE4 answerhub where questions go back to being unanswered if the original author or person who responds adds a comment again. I think you have to mark it as answered again after commenting. That seems like a serious flaw to me.