- Home /
RPC not sending and not giving an error?
So I'm working on a networked game and so far I've had no problems with RPCs aside from random user error, but this one is baffling me. Every iteration of the while loop in BeginReport I get the "Reporting" debug line on the client as intended. On the server, however, "Report Reached The Server" never shows up. I took a look at the stats tab and it was showing only 2 sets of packets being exchanged between the server and client, always the same size and at the same time intervals so most likely handshaking or something but never anything else. I know it's something absolutely stupid but neither myself, nor anyone I've shown can make heads or tails of what's wrong.
The code is below, ignore the somewhat verbose function calls, I was doing testing.
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(NetworkView))]
public class ReportOnLevelLoaded : MonoBehaviour {
bool receivedConfirmation = false;
void Start () {
if(Network.isClient) {
StartCoroutine("BeginReport");
}
}
IEnumerator BeginReport() {
while(!receivedConfirmation) {
Debug.Log("Reporting");
networkView.RPC("ReportToServer", RPCMode.Server, Network.player);
yield return new WaitForSeconds(0.1f);
}
}
[RPC]
void ReportToServer(NetworkPlayer player) {
Debug.Log("Report Reached The Server");
LevelLoadedCounter llc = gameObject.GetComponent<LevelLoadedCounter>();
llc.ReportIn(player);
}
[RPC]
public void ServerReceivedReport() {
receivedConfirmation = true;
}
}
Does the server have this actual representation of a ReportOnLevelLoaded attached to it? RPCs go to the same object on the server - i.e. the one with the same NetworkViewID.
They do? The documentation says an RPC call will call just whatever function it finds. So if you have "Func" on every component, the RPC call will just find the first object with a "Func" function and run that. Says the documentation. $$anonymous$$aybe. I took it at what I thought its word was and wrote around that without testing it.
are you successfully connected (use OnPlayerConnected to quickly check that)?
It certainly doesn't call every function on every script with a networkView attached. It has to call on the scripts on the object you are targeting.
So if you address this to a non-existent NetworkView, nothing will happen.
@whydoidoit Yes it's there, that was the first thing that I checked. @Loius This is also true, whydoidoit might have used the wrong word but it can call any function on an object which has the same NetworkView. In this way I typically set up 2 scripts, on the same object, one for the server logic and one for the client and make calls back and forth between them.
Your answer
Follow this Question
Related Questions
Is server the sender of RPC? 0 Answers
networkView.RPC() inside a ScriptableObject 1 Answer
Where is a free, helpful tutorial on how to use Unity's networking? 2 Answers
Which is better: NetworkView or RPC? 1 Answer
View ID AllocatedID: # not found during lookup. Strange behaviour may occur 1 Answer