How to execute events only on a certain client

So i’ve been trying to make my own game in UE4 with multiplayer, but i’m getting these 2 issues that i can’t really get past:

1 - The health bars on top of the players won’t change rotation (they’re snapped to the player), and i wanted each client to rotate all the health bars in the server to it’s orientation, but only that one client, so then i would do that to every client and each one of them would have every health bar facing them. I tried using a tick event on every player to do this, but nothing would happen (probably because the health bars are snapped to the player blueprint).

2 - The game involves shooting projectiles (spheres) and i had them change color in-game. What i wanted to do was have the projectiles change to a certain color on every client but the one who shot it, and to some other color only on the client that did shoot it. I tried many different setups and didn’t get it to work, but there might be something i have to change: what i did was when the projectile is supposed to change color, it’ll execute a multicast function on the projectile blueprint, but then use the projectile’s instigator (which is properly set) to execute a function from its player character blueprint, but only on owning client. That function would in turn execute another event from the projectile blueprint that would change its color to the desired one (supposedly only on this client).

I know this is very confusing, but it’s the only way i could think of executing this. Surely there must be a more simple way to do this…

Please help!

[ANSWER TO QUESTION 1]:

Feel free to let me know if you want details, but essentially you do the same thing but set the widget component to screen instead of world.

[ANSWER TO QUESTION 2]:

To shorten what was discussed, you need to set the projectile’s instigator (or variable that holds owning player’s state) to the player that just shot the projectile. On the projectile event graph, you handle the collisions on the server, create a variable named walls hit and set it to RepNotify. On the OnRepWallsHit function, you use Get Player Character to cast to you character blueprint (in my case FirstPersonCharacter) and compare that to the projectile’s instigator/ owning player state, and then build your logic on top of that.

For your particular case, determine color on begin play in projectile.

For future reference, to execute something on some exact client, you would need to call RPC event from server to owning client on player controller.

in Blueprints you use Events for RPC, so yes, its quite simple as far as you dont need full prediction.

I don’t know how you would be able to do it. You’re asking for a replicated widget to not be replicated but different for every client.
I would recommend making the health bar above other peoples heads a part of the clients hud, not a part of the actor itself. So each client just reads the health values but makes it’s own umg widget above every players head. Should circumvent your problem.

I thought about that, but wouldn’t that harm the performance, given that say, if i have 16 players in the server, every single one of them would have to constantly draw possibly 15 health bars on a tick event?

But yeah i can’t really think of another way to circumvent this issue.

Does it make a difference if i have a variable that contains the default color and then use that variable in the construction script?

Not, i dont think so.

I tried what you said (i think) but am still having issues.

When the projectile is supposed to change color, it executes a Run on owning client event from its instigator (this is being done correctly), and that event then executes another event from the projectile blueprint (which i dont know whether to make multicast or run on client) passing the projectile as an input that was also received from the first event.

Really the only difference i’ve made from the original graph shown above was to pass the projectile actor as an input to the Change Projectile Color 1 and 2 and use that to cast to the projectile blueprint…

Still not working though :confused:

Not on owning client, just change color, like directly after begin play.

Oh, but i want this to happen mid-game, not just when the game starts, in fact this can happen twice in the game… sorry if i didn’t make myself clear.

I guess we don’t talking about projectile color anymore, so what are we doing? Can you actually clarify what exactly gameplay mechanics are you trying to implement, there are dozens of ways doing what you described.

Well what’s going on is the projectiles each player shoots change color twice: when they hit 1 wall; and when they hit 2 walls. I want every player but the one who shot the projectile to see those colors respectively as red and black, but then i want the player who shot it to see it as green and blue (the default color of the projectile is orange). So the color changes every time the projectile hits a wall but it has different colors depending on whether you shot it or not.

Was that clear enough? :stuck_out_tongue:

So, your projectile should have Player State type property in it, because it exist on all clients and that’s the place where you could save team or so, so all clients have access to this data, property should be marked as replicated and expose on spawn.
When server spawn projectile it should be using shooter Player State.

On Projectile begin play you would call the logic which determine what color projectile should have.

About wall hit, you can :

a) Detect wall hit locally and change color.

b) Create integer rep notify variable “walls hit”. Detect Wall hit on server and change variable. On RepNotify function is this variable change color of the projectile(this function getting called on every client and server every time when variable changed, so it would work).

Was that clear enough? :stuck_out_tongue:

So do i send the player state from the player to the projectile? (sorry didn’t really know about player state before you mentioned it, i did a bit of research though)…

Also how do i change color only on the clients that have a different player state?..

Thanks for the replies btw! :smiley:

Create a variable in projectile, you unique Player State type, mark it expose on spawn and replicated. When you spawn your projectile, you can put in shooting player player state (you can get it from player controller) and on begin play determine color based on data saved in this Player State, without any RPC events, it would be called on all clients.

I created a variable of type Player State in projectile and set it to the shooting player’s Player State when i spawn the projectile, but i’m still kinda lost on “on begin play determine color based on data saved in this Player State”.

Also i didn’t get the “unique” Player State type.

By “unique” i mean your “own” class, created as asset, which contains important data and setted up in game mode as default player state.

By “determine…” i mean : You have idea what color each player represent, something like team i guess. So you store team as replicated variable in player state and populate it On Post Login in game mode or something.

When projectile begin play happens, since you have shooter player state stored, you can get team from it, also you can : “get player controller” (index0) → “get player state” which would give you current local player state. Now when you know shooter team and local player team, you can make whole thing work.

I still don’t think i explained everything correctly… It’s supposed to be a free for all game. The only projectiles that you see with a different color are the ones you shot. By default everyone sees the projectiles as orange when they are fired (spawned), but when the projectile hits a wall, if you’re the one who shot that projectile, you’ll see it as green, whereas everyone else will see it as red. That is what i want.

In this screenshot, the player on the right shot the projectile, and both players are seeing it as red, but i want the player who shot it to see it as green (the one on the right).

I’ve already answered it, even if not directly at this point you should figure out. Its start turning from help me to learn to do it for me. Last one.

“When projectile begin play happens, since you have shooter player state stored, you can get team from it, also you can : “get player controller” (index0) → “get player state” which would give you current local player state. Now when you know shooter team and local player team, you can make whole thing work.”

^ or you can just compare local player state with projectile one, if they are equal that client is one which shoot the projectile.

hit wall thing:

“Create integer rep notify variable “walls hit”. Detect Wall hit on server and change variable. On RepNotify function is this variable change color of the projectile(this function getting called on every client and server every time when variable changed, so it would work).”

^ again, compare player states, if equal change color in one way if not in another.

It’s working! Thank you so much!!!

I did everything the way you said, the only difference is i used get player character to cast to the client and not get player controller, but everything else was correct!

My confusion was casting to the client on the RepNotify function…

Thank you for your patience :wink:

Do you think i should make a short description of the process in the question, or would you rather have your knowledge concealed? :stuck_out_tongue: