- Home /
Figured out the problem
Mirror: Linking Login Info with the player
I have a multiplayer mmo-like game project using Mirror with an account log-in system. The first scene is the Login menu and upon a successful login it switches to a scene with all the networking stuff, allowing you to host or connect to a client. Upon connection, I'd like to be able to link the name of the player with the username used in the login from the menu.
I can't seem to figure out how to do this using Mirror's Network Manager and Network Player relationship. The best idea I could come up with is have a gameobject with DoNotDestroyOnLoad that logs the username as a variable and carries it over to the scene, where the player looks for the gameobject and sets that name as its own. However, this has it working for the first player, the host, but every subsequent player that connects gets the same name as the first. I guess I thought the player would take the name from the current game, the same one where they log in, but it seems like the only gameobject that can be accessed is the one holding the name of the player that's hosting, which is in the same game as the host network manager. How would I make it so that each player has their own respective name?
Answer by ddooms · Jan 07, 2021 at 08:51 AM
The problem with this is that the master is the one that "owns" the object. What you need to do is instantiate an object for the player and set that objects ownership. However I feel this is a bad implementation. What you should do instead is instantiate s class that holds information about the player that doesn't compromise their account, like usernames. Instantiate the class, set it's information to reflect the player, and then set the ownership to that player (this usually happens automatically in photon, unsure about what you're using). Then I would check all instances of the class to see if it belongs to the player (isMine in photon) and grab the correct one to get their information.
Follow this Question
Related Questions
Smart fox+Mysql+unity=log in? 0 Answers
Multiplayer Game Highlight Material 0 Answers
Server game object not syncing position after if statement 0 Answers
I have a script that work fine with mirror but visual studios is reporting false negatives 0 Answers
Mirror: Connecting android mobile devices together? 0 Answers