'Set player names with mirror networking in chat system

Code link: https://justpaste.it/8kefo

I had a problem with my code, the code is a chat system made using mirror networking, I followed a tutorial from "Dapper Dino", and I modified the code to display players usernames, anyways, when I run the game the username shows, but the problem is that the username is always the host's username, even if message was sent by client.

I have no idea what to do, but I think I know what the problem is, I think that the problem is: The username is a string inside a class of the type NetworkBehaviour, so the playerprefs that gets called is the host's playerprefs and not the client's, basically because its called in the server.

Edit: I also tried to set the username with "override void OnClientStart()", but it did not work.

Edit 2: I Finally fixed the error by adding a username slot to the "CmdSendMessage(string message)", so its now: "CmdSendMessage(string username, string message)", so the error was that I added the username text inside the "CmdSendMessage", which is always called in the server, which always got the host's username, but now I called the "CmdSendMessage" function from "Send(string message)" function, which is called on the client.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source