Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question [Mirror] NetworkServer.ReplacePlayerForConnection replaces player, but client has no authority.

Discussion in 'Multiplayer' started by wztk, Jan 18, 2021.

  1. wztk

    wztk

    Joined:
    Feb 25, 2020
    Posts:
    30
    Hi guys,

    I'm having a problem with replace player function. Basically, I'm swapping scenes directly from client and once scene has been changed, I have my network manager call command from one player object to another. The command looks like this:
    Code (CSharp):
    1.     [Command]
    2.     public void ReplaceRoomPlayer(GameObject player)
    3.     {
    4.         if (!isLocalPlayer) return;
    5.         NetworkServer.ReplacePlayerForConnection(connectionToClient, player, true);
    6.     }
    7.    
    This code is executed properly and the player is spawning, but the connected client has no authority over the spawned object and therefore I cannot interact with the object on the client in any way.

    I'm not sure why this is happening, I've tried getting connectionToClient from the new player object and instantiating it inside this command (as I've heard gameobjects can't be passed through commands), but the result is always the same.

    Can someone help me out with this?
    Thanks in advance.
     
    Last edited: Jan 19, 2021
  2. wztk

    wztk

    Joined:
    Feb 25, 2020
    Posts:
    30
    Just as I was about to give up on Mirror altoghether, I found the solution, although it doesn't work perfectly.
    The problem was the isLocalPlayer check, once that's been removed the player actually spawns, but it gets kinda glitchy with other players.
     
  3. StarShade88

    StarShade88

    Joined:
    Jan 28, 2020
    Posts:
    4
    I know, it's a little bit too late, but your command is useless. Commands are functions, that run on the server! So if you make the check "if (!isLocalPlayer) return;" it always returns, because the server doesn't have a local player.
     
    IrishCyborg and Thunderik like this.
  4. wztk

    wztk

    Joined:
    Feb 25, 2020
    Posts:
    30
    Well, that was really unnecessary seeing as I've already mentioned it and in general the issue is unsolvable, but I guess whatever floats your boat.
     
  5. vromain

    vromain

    Joined:
    Aug 18, 2020
    Posts:
    3
    I think removing the islocalplayer check will allow you to move control your characters but you will face situation where one player can take control of another player character...
    This is a super glitch, and I think you shouldn't do that.
    I facing the same issue but even on [client] my spawned object don't have authority...
    I'm struggling with that from a couple days
     
  6. oli-2019

    oli-2019

    Joined:
    Aug 2, 2019
    Posts:
    4
    not sure if it is wise to resurrect this year old thread and in the mirror discord you'll probably find better and faster help.

    Are you using Client or Server authority for your players?
    What do you mean by "[client]"? Are you refering to the "[Client]"-Attribute (https://mirror-networking.gitbook.i...?q=servercallback#server-and-client-functions)
    the ReplacePlayerForConnection should be called on the server side!
     
  7. vromain

    vromain

    Joined:
    Aug 18, 2020
    Posts:
    3
    I'am using client authority on my network transforms and network transforms child.

    Yes by "client" I mean [Client] attribute.

    My scenario is :

    Somebody host a lobby and the other one join it.
    Each time somebody join, it connection is added and an empty object with network identity is spawned.
    When everybody is ready, the host can start the game.
    At this time we got a server changescene and on it callback the server spawn a character selection ui.
    The player choose his character and click an "ok" button that launch a replaceplayerforconnection (still on the server) and hide the ui.
    I dont know why but the spwaned object always got hasauthority as false.
     
  8. vromain

    vromain

    Joined:
    Aug 18, 2020
    Posts:
    3
    I checked the client authority box on every playerprefab