Array replication to all clients

Hello guys. I am creating a small chat application. The client writes a text in a textbox. After doing this he adds his text to an array. Now the server should pass this array to all other clients with a multicast function. This is just the theory because every client has its own array object. Is there a possibility that every client has its own array and if a string was added that the server sends this array to the clients and replace their arrays ? Ans ideas ? Thank you for helping.

EDIT: My chat application was working fine with a multitextbox and just a one line text. But that was not a solution for me.

You could send each string to each client using an RPC call, this way you do not have to hold an array to be replicated, which will be very inefficient when the array grows. You could also set a string in the PlayerState of that player to get replicated to all clients the string would represent the last chat message that this client shouted, you might loose some messages if the clients is fast and sends two or more messages, but if you add them to a queue and submit the message one after another with a small delay it should be fine.

So to clarify, what I propose is that the client sends the chat message to the server, the server sends the message to all other clients (to their PlayerControllers) and not the entire array. Or the server sends the message back using variable replication instead of a function.

Thats really close to what I am already doing but it won’t work. List Item is not replicated.

Here an example:

But what I’m suggesting is not replicating the array but instead replicate only the new string. You should avoid replicating arrays whether that is possible, replicating dynamic arrays comes with quite a bunch of issues: https://docs.unrealengine.com/latest/INT/Gameplay/Networking/Replication/Implementation/DynamicArrays/index.html

Yeah I know Sir, but its not possible to create it without an array. its only possible to list up items or strings or whatever by using a scroll box /vertical/horizontal box and this only by an array. I tried out your methode and it makes no difference to the first one. I pass a string to the server the server is passing this string t the clients. Everything works fine until now. Now I gonna add this string to an array (Clientside). Works!. But if I run the game on another client it has its own array :frowning: Also if i would insert this into a string variable client or serverside so every client would have its own string.

Here is quiet simple how I get this string:

If a new client connects that one will receive the new messages when they arrive, I do not get what the issues is you are describing right now, why you are not able to just store the incoming messages on the client side. If you would like to send all already sent messages to each connecting client I would make an initial replication with some messages, but normally games with chat wont do that.

When you open/close the widget it get reinitialized and so nothing has been ever set to it, so why not storing the list of messages locally in your PlayerController for example and just publish the changes to the widget, each time you add a message to the list of your PlayerController you add it to the widget. The same applies when you open the widget, just add all items from the list to it.

I tried to pass a single string from client to server. Check! Worked!. Afterwards the server takes the string and pushes it to the clients. Check! Worked!. Then it adds a text block to the parent widget.Check! Worked! But if a client closes ( remove the widget from viewport) the widget or would reopen it, everything inside the widget is gone, so I have to store the text messages (Clientside) inside an array. And thats the solution I am searching about. No matter at the moment if an array could be too big because I gonna handle it later ( lets say only 10 messages, so that a new message comes in and the oldest falls out for example).

Isn’t that exactly what I am already doing ? Only change is that I am inside MyCharacter BP and I am storing the information inside an array clientside, like you can see on my last posted picture. Maybe we talk at cross purposes or I can’ t follow your idea. Everything in the multicast is running clientside or ? So I am passing my string to the server and then to the clients which adds it to this text array.

yes we are talking about the same thing I guess :smiley: I just added how to prevent the list get emptied. Is there any issue left?