Multiplayer OnOverLapBegin called in every actor at once

Backstory:
I’m working on a multiplayer game

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:

OverLap method declaration in header.

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.

There is also another question about the same topic, I raised mine because he/she did not get an answer.
Link to the other post: https://answers.unrealengine.com/questions/810987/my-trigger-box-detects-all-of-my-characters-when-o.html

Hi, you can create your collision shape only on server side and handle all overlaps only on server ?

Instead of HasAuthority() use IsLocallyControlled()

I think event is raised to all instances because usually character (and character movement) replicates due to inheritance.

IsLocallyControlled will be true if it runs in your particular client.

Hi,

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 :frowning:

Hi,

Thank you for your answer, just to clarify, are you suggesting me to use an RPC function, resulting me always only triggering the overlap on server?

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).