Hi,
I’m trying to implement a chat system where player text messages should appear on top of players like in the ultima online.
The system that i implemented works fine but i’m not happy with it.
System spawns a text mesh on the network when player enters an input.
Input in the text mesh updated with the usage of syncvar variable for all clients.
Rotation of text mesh updated with the rotation of main camera for local player.
If i can not find a better solution i will implement position syncronization of text meshes for to follow the user who write it and text mesh will be destroyed after an 3-5 second from creation.
This system will cause lots of text mesh objects to syncronize with clients. When client number gets higher, it will consume lots of network traffic. That’s just a simple bad thing with this implementation and it is already tempts me to thing about it.
When i’m using just string variables to syncronize with all clients. I do not know how to handle position of text messages to get sync with users position (on top of users) when showing them with GUI.Label etc…
Or how to know which message written by which player.
If you have any ideas or guidence to share with me, it will greatly appreciated.
If you send a chat message from the client to the server, you can also add a second parameter to that function with the NetId of the player object. That way, you’ll know what player a message belongs to, and you can let all clients locally instantiate and destroy a text mesh after only receiving a single ClientRpc with two parameters. That doesn’t sound like too much bandwidth to me?
You still should instantiate text meshes with network.spawn() because all clients should see the all messages on top of players. The idea still the same.
I do not want to instantiate all inputs as gameobject. I thought it will give so much overhead.
Thanks anyway
Why can’t the text mesh be parented to the player already, but just visible when there is something to display? I really don’t see why you need to have the actual text mesh object to be spawned by the server when all you need to do is update the content text.
and in the player prefab with the script attached, drag the child mesh into this slot on the script. Then you can reference it from code in the player script.