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:
[Command]
public void ReplaceRoomPlayer(GameObject player)
{
if (!isLocalPlayer) return;
NetworkServer.ReplacePlayerForConnection(connectionToClient, player, true);
}
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.
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.
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.
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
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.