UNET Scene Object RPC
I am writing a chat window. Child to the chat window is a Network component with commands and rpc's for sending and receiving messages. With Legacy networking this works as expected, no pain. With UNet nothing I do works.
When I use a scene object with a NetworkScript I get this error on my clients
Trying to send command for object without authority.
So I look into spawning my network component on on startup...
And I learn that clients can not spawn objects...
I tried adding my NetworkComponenet to the NetworkManager "PlayerPrefab" and It is not spawning as expected either.
So... How exactly am I supposed to go about this ?
Answer by GunLengend · May 24, 2016 at 05:49 AM
That because you are try to send command from GameObject without Client Authority. Only GameObject spawn by NetworkServer.SpawnWithClientAuthority and any GameObject check with Local Player Authority checkbox in NetworkIdentity can send command to Server.When I use a scene object with a NetworkScript I get this error on my clients
To spawn player GameObject :So I look into spawning my network component on on startup...
Client side :
1. Register this player GameObject to spawn system by :
ClientScene.RegisterPrefab(playerPrefabs);
2. Set client to be ready:
ClientScene.Ready(connection);
3. Call server add player :
ClientScene.AddPlayer(connection,0)
Server side :
1. Register addplayer listener ( if you using NetworkManager, just override OnServerAddPlayer function and ignore this) :
NetworkServer.RegisterHandler(MsgType.AddPlayer, OnServerAddPlayer);
2. Instantiate player GameObject on Server:
GameObject player = Instantiate(asset) as GameObject;
3. Make client SpawnPlayer:
NetworkServer.AddPlayerForConnection(netMsg.conn,player,0);
That's all
Your answer
Follow this Question
Related Questions
Dynamically generating platforms other network 1 Answer
Is there any benefit to calling NetworkTransport.Receive multiple times per tick? 0 Answers
UNet - sync child transform scale 1 Answer
Photon Voice chat and Speech to text plugin not working together 0 Answers
TrailRender not showing in all clients using Mirror networking 1 Answer