- Home /
ClientRpc not called on Client
Hi all,
I'm hoping for any help on this one. I have some code that is called on a NetworkServer.Spawn()'ed object:
class InitClass : NetworkBehaviour
{
[ClientRpc] public void RpcInitialize() { print("initialized"); }
override public void OnStartServer() { RpcInitialize(); }
}
This method does not get called when I run the client in editor. But it does get called when I host from editor.
I have tried setting the object to server only
but still nothing.
Any help is appreciated.
Thanks,
Answer by Bunny83 · Mar 14, 2018 at 02:22 AM
Well your setup doesn't make much sense. OnStartServer is called when the server is initialized / started up. At this point no client can be connected. So the rpc won't reach anyone. RPC calls are not buffered. So when a client actually joins the server the object get created on the client but of course it won't receive the RPC unless you send it again.
You usually use the OnStartClient callback to do any initialization on the client side. However if you keep your relevant state in SyncVars you don't have to do anything. If a new client connects to an already running server all tracked network objects will be spawned automatically on the client and they have their syncvars updated to the latest state from the server. OnStartClient will be called afterwards.
Your answer
Follow this Question
Related Questions
Network how to send data/activate function 1 Answer
RPCMode.Server works in one spot but not another 0 Answers
What's the best approach for creating a secure authorative server? 0 Answers
Server still sending Packets to inactive clients and throwing errors. How can I stop it? 0 Answers
Totally lost with UNET - Client to Server Networking 3 Answers