I have two scenes. One is responsible for matchmaking (so it has Lobby and Relay components) and the next scene has the actual game (so it has a NetworkBehavior for RPCs).
Now my NetworkBehavior doesn’t work which I’m guessing is because the NetworkObject component isn’t set on account of it being in another scene and the NetworkManager + Unity Transport components being in another scene.
On the server, the NetworkBehavior object is set to empty with the “Spawn” button being enabled during runtime. If I click on the Spawn button, it fills in the details on the object and on the clients it gives an error. If I try to pass any RPCs between the servers/clients, all the receiving peers show that the message was delayed by a second in the debug logs and don’t do anything.
I’m just calling the various RPCs I’ve defined in the NetworkBehavior.
I’m not setting the authority explicitly. So I think each device/game instance has its own copy of the object and has authority over that? I didn’t go too deep into trying to understand this system as I got my game working earlier without setting authorities/spawning multiple objects. Let me know if you think that’s the wrong approach. Since I’m making a board game (like chess, but there can be 4 players and each player can have dozens of pieces), I didn’t want to create a NetworkObject for every piece and as per my understanding, I can just use it to pass messages between peers.
By empty, I mean none of the properties of the component are visible in the inspector. I’m talking about the NetworkObject component that gets auto-added to any object that has a NetworkBehavior script.
So for example I have:
class RPCClass: NetworkBehavior
{
[ServerRPC]
public void DoSomethingClientRPC(){}
}
I’ll call it like this:
class SomeScript: MonoBehavior
{
public RPCClass refToClass;
public void OnSomeEvent()
{
refToClass.DoSomethingClientRPC();
}
}
Both the scripts are in the same scene, but on different objects.
If your method is a [ServerRPC] its name has to end with ServerRPC. It’s not working because you called it DoSomethingClientRPC. The correct name would be DoSomethingServerRPC.
@PaoloAbela hey, sorry for the confusion. It was a mistake here, I am actually using the right method names in my project. So in the project, it is actually DoSomethingServerRPC
Ok, has the object with RPCClass being spawned over the network (not just in the scene) when you try to call that method? Do you have any logs in the console?