Hi there,
i’m struggling with my chat-text replication. I just can’t get it to be replicated to all clients. I only see the text on the local client who submitted it. What am i doing wrong? Why is my multicast event not working properly?
I hope you guys can help me out.
These are my two blueprints, my widget blueprint and my battlecontroller:
I think the problem may be that your Multicast event is in a user widget. I’m not sure that you can replicate events in a UMG widget itself. You need to use something like a controller to do the replication part and then it’s the controller that tells everyone to update their widgets.
What I would try (assuming BattleController is a player controller):
Change the ChatMessage event in your widget back to a normal, non-replicated event.
Create new event in your BattleController (let’s call it “ReplicateChatMessage” for now) just below your current nodes, with a “Chat Message” text input like your ChatMessage event.
Make ReplicateChatMessage a Multicast event.
Replace the call to ChatMessage with the new ReplicateChatMessage
Make ReplicateChatMessage call the ChatMessage event in your Chat Window.
So if I’m correct what should happen is that on text input, your chat window widget will tell your controller that a new message has been entered. Your controller will pass the message to the server. Your server will then call a Multicast event in the controller instead of the widget (I think this is the key part), at which point all client controllers will call a local event in their own respective chat windows to update the text.
Shouldn’t NewChatMessage be a Run On Server event? Or is it just a visual bug (if you change an event replication type it doesn’t visually update unless you hit F2 on it to rename it)
Thx for your answer!
Yes BattleController is a player controller.
i tried your solution, but unfortunately it’s still only working on the local client -.-
Maybe put some print string nodes at the beginning of each event just to see what is firing on which players and where it stops working? That’s usually how I debug everything when it comes to replication.
Alternatively, what you could also do is have New Chat Message (which is Run on Server) change a RepNotify text variable in GameState (its preferable to have that stuff in GameState than your player controller since the game state exists on everyone).
Then on the OnRep funtion of that variable (the OnRep will fire every time the server changes that variable, on all clients), you take the content of the variable and put it in your chat box.
Hey,
I tried to put the whole BattleControllerStuff into GameState. It didn’t change anything, except the fact that my NewChatMessage event only fires, when i change it to Not Replicated.
Is it possible that my initial setting of my Chat Window is done wrong?
Probably i didn’t quite understand you, could you explain your solution a little further?
Here are my BattleController, the GameState and my Widget blueprint.
Sorry, i can’t really follow you.
Do i create the RepNotify variable within GameState or within my Widget blueprint?
If i create the variable in GameState and set it through my NewChatMessage event (which somehow does not fire when i change it to Run on Server, only when not replicated). How can i set my Chat Message within the OnRep function.
I’m a little confused here, with all that back and forth jumping, i’m really glad for your help, could you explain that solution a little further?
I did quite a confusing mix between GameState, PlayerState and a RepNotify variable. I am still not quite sure why it didn’t work with either only GameState, or only PlayerState, do you have an answer to that? Thx a lot for your help! If you have any further improvements, or ideas how to do it easier, i’d be glad to here them.
Btw, what i realized later is, the server isn’t doing anything in my gamestate. It cannot set the replicated variable, because it doesn’t have the Chat Window widget.
It works because the variable is set to the same Chat Message on all clients.
I think the solution is a little dirty, but as it’s working i don’t care anymore