I have an event on hit assigned to a block. When hit, its supposed to assign death to the player who hit it. Then its supposed to call a function that displays a string of win/loss to all players in the game. If you didnt hit the block you win, if you did you lose.
The problem is the function needs a target. I can target the hitting player just fine. But I want to target everybody in game. Either way, every player in the game (idealy two people) need to see if they win or lose after someone hits the block first.
Try using the GetAllActorsFromClass node and get all character blueprints or player controller blueprints, you could use either. Just make sure that when you do it, you are doing it inside the server by using an authority switch. You need to do that because only the server holds a reference to every player controller in the game, in the client only his own player controller exists. And as for characters, they all do exist on each client but just remember that you can’t call Server functions on them since they are owned by the other clients, you can only call server functions on the player that you as a client own.
Look I did a quick test and it worked quite nicely!
Note that the WinLose event is defined inside my controller class but like I said you could do the same using your character class instead I just thought it was better to put it in the controller.
Every player pawn (or controller or whatever) would bind a custom event to the Event Dispatcher.
The block calls the Dispatcher when someone touches it. The “Someone hit the block” event would thus fire on all players.
Then you set up the inputs of the Event Dispatcher, which would allow the block to send information, such as the name of the guy who just touched the block.
Event Dispatchers are the simplest way of getting a blanket message to a bunch of listeners. They specifically help you when you have no clear idea of who will receive the message - it’s the listeners that have to take care of that, not the sender.
This is roughly what it would look like in the player pawns:
Once the “Bind Event to DeathMessage” node has been used, the pawn will listen for the “DeathMessage” Dispatcher to be called, which then causes “Someone just died” to fire.
This is roughly how the block (or whatever is most convenient) would call the Dispatcher:
Yes, it really is this simple, unless I’m missing something about multiplayer that would make this harder.
Yes, there are various things to consider when you are on a multiplayer game. For example, are you executing code on the server or on the client? and on which of the clients. And what type of RPC are you using and who owns (server or client) the actor where you are calling RPCs. You have to code with a whole different mindset.
Thank you so much for your detailed reply. I’m new to authority, loops, and slightly arrays. But I’m learning. I’m slightly busy but I will try to look into these things tomorrow and get back with you. Again, tremendous help man.
Hey, thanks man. I’m unfamiliar with dispatchers but they look like they might be a quick and easy solution. I’ll look into them soon and get back with you on it.
Progress report. I did on event hit instead of overlap, but everything else is the same for the object. As for the ThirdPersonCharacter, everything is the same except get player character instead of controlled pawn.
The issue being that when one person steps on the cube, it displays the message twice, and whether or not you are dead. So one guy steps on it and both players see, You are dead, You are dead.
Before I had the branch condition as JUST dead instead of player = dead like you had it. Then it said something like You are dead, You are alive, to both players on screen. If that helps you troubleshoot at all.
Its possible I messed up with the events and how to call them and such, that was a little new to me. But it seems like that works fine. Its just an issue of seeing every players individual message. And then now its an issue of seeing the death message for two people. (only two people in game). With three connected it sends three messages to display.
Ok try this. Click on the WinLose event node. The red one. A panel on the right should appear. There should be an option that says replicate which is probably set to not replicate. Change that to Run on Owning client
Ok just a few more things. First make sure that this block is an actor that is being replicated. So go to the CubeGroundTest blueprint in the left panel on the self component. Look for the replication tab and check the box that says replicates.
And secondly make sure the character variable Dead is set to replicate. To do it just click on the variable and a panel on the right should pop up, set the replication option to replicated.
Edit: I just saw another little detail. In the win loose event you are using the GetPlayerCharacter node to get the dead variable. But the thing is that you don’t need to do that. Just get the variable, since you already are inside the Character blueprint.
Did everything you said, same result I think. If you play, then touch it with the editor player it says client 1 you win and server you lose (to both players). If you touch it again with either both are lose. If you play then use the second connected character and touch it first it says server you win client you lose, then lose for both after second touch with either.
But yeah a lot of things I had set to not replicate, but still not getting ideal results now.
That should work, I have it set to view not edit. Should be able to right click the zip, download, then unzip it when its downloaded. Note that you do have to be signed in to google to be able to right click on the file and download it.
Then of course drop it into your unreal projects folder.