Problem:
In my game there are 4 players. In the map I have a triggerbox, if one of the Characters overlaps with the triggerbox, it is activated in all of them.
My overlap begin method cpp:
If one of the characters overlaps with the triggerbox then all the characters see in the left corner:
I am Host
I am Client
I am Client
I am Client
One thing i noticed is that it is always in that order, meaning the Host executes the trigger first every time, even if a client overlaps with the triggerbox.
I do not understand why the it is triggered in all of the players, I would like it to be triggered only once by the character that is overlapping the triggerbox.
Thank you for your answer, unfortunately I did not find IsLocallyControlled() using c++, I found it can be used with blueprint.
In C++ i found GetWorld()->GetFirstPlayerController()->IsLocalController() and GetWorld()->GetFirstPlayerController()->IsLocalPlayerController(), but they did not give me the result i was expecting
I dont know exactly what are you doing. But I suggest create collision shape only on server side. something like this:
// in constructor - creating your collider only on the server
if (Role == ROLE_Authority)
{
/* sphere collision */
SphereCollision = CreateDefaultSubobject(TEXT(“SphereCollision”));
SphereCollision->SetupAttachment(RootComponent);
}
and handle all logic only on server. If you need some FX replicated to client whenever trigger is overlapped you can use Rep_Notify. If you for instance need to simply destroy overlapped actor you don’t need Notify at all. Destroy overlapper on the server in the end of game logic and play required FX in blueprint in EventDestroyed. Some ways exists. Choose whatever you like.
from the overlapping event - get other actor (it’s your pawn/char), then cast to pawn and from it, you can check If pawn locally controlled.
trigger fires on all players because all they have a local copy of this trigger. and also they have replicated copy of each other. when this replicated copy of player overlaps this trigger, then this client receives the overlap message from his local copy of trigger (I’m overlapping with another player that you can see, he replicates on your machine with his replication movement component).