- Home /
RPC-Function not Called, but no Error
I have a Problem with an RPC-Call, where an Enemy should be called on the Server-Side. Here is the Code:
function Awake() {wallWalker = Resources.Load("WallWalker") as GameObject;spawnWallWalker();}function resetOther() {if (spawn) {GameObject.Destroy(spawn);}spawnWallWalker();}function spawnWallWalker() {if (Network.peerType != NetworkPeerType.Disconnected) {//Only Spawn Wallwalker on ServernetworkView.RPC("spawnWallWalkerRPC", RPCMode.Server);} else {spawnWallWalkerRPC();}}@RPCfunction spawnWallWalkerRPC() {if (Network.peerType != NetworkPeerType.Disconnected) {spawn = Network.Instantiate(wallWalker, transform.position, Quaternion.identity, 0);`} else {spawn = GameObject.Instantiate(wallWalker, transform.position, Quaternion.identity);}spawn.GetComponent(WallWalker).spawn(transform.position, horizontalMax, verticalMax);}
Everything works fine, except after networkView.RPC("spawnWallWalkerRPC", RPCMode.Server); the Function spawnWallWalkerRPC is not called, and Unity does not display an Error.
I really have no Idea where the problem lies, maybe I'm missing something obvious. Help is very much appreciated.
Are you calling this code on the server? RPC$$anonymous$$ode.Server doesn't work on the server
As whydoitdoit said RPC$$anonymous$$ode.Server doesn't work if the player sending the message is the server. You need to add a check for Network.isServer and if so, just invoke the function, not as RPC.
Thanks whydoidoit and asafsitner, that was the solution. Thanks again.
Answer by whydoidoit · Jun 28, 2012 at 09:34 PM
You cannot RPC a function on the server using RPCMode.Server from the Server itself. You need to directly call the server function when Network.isServer returns true.
Your answer
Follow this Question
Related Questions
Send GameObject active in network to all clients 2 Answers
Disconnect a player from a network 1 Answer
Network.Destroy(), Couldn't perform remo 0 Answers
RPC call not sending correct data 0 Answers
Empty RPC functions. 1 Answer