SendPawsToServerRpc Method Not Being Called in Multiplayer Project with Netcode

Hi Unity developers!

I’m facing an issue in my multiplayer project using Unity Netcode for GameObjects. The SendPawsToServerRpc method in the BattleServerManager class is not being called, even though it should be. I’ll detail how the project is set up and the problems we are encountering.

Project Setup:

  1. Game Objects in the Scene:
  • Player: Each player is instantiated as a prefab that includes the PlayerDataManager script.
    • Components:
      • NetworkObject: Required for Netcode synchronization.
      • Script PlayerDataManager: Manages player data, including a NetworkList of “Paws” (characters).
  • BattleServerManager:
    • Responsible for server-side logic, such as spawning Paws and coordinating the battle.
    • Components:
      • Script BattleServerManager.
  1. Player Prefab:
  • Registered in the NetworkManager as the player object.
  • Successfully instantiated in the battle scene (BattleScene) when the match starts.
  1. PlayerLeft and PlayerRight Objects:
  • Represent the two sides of the battlefield.
  • Both have the NetworkObject component.
  1. Game Flow:
  • The match starts, and players are successfully connected.
  • The OnNetworkSpawn event in PlayerDataManager is triggered for each player.
  • Player data (e.g., Paws) is sent from the client to the server via ServerRpc.

Logs and Problem:

  1. Successful Logs:
  • The UpdatePawsOnServerRpc method in PlayerDataManager is successfully called.
  • The log Notifying the BattleServerManager about the player's Paws SwiftHawk722. appears on the server.
  1. Issue:
  • The SendPawsToServerRpc method in BattleServerManager is not called.
  • The log Receiving Paws data from player {playerName} of client {clientId}. does not appear.
  • There are no apparent errors in the Unity or server console.

My Hypothesis:

I believe there’s an issue in the communication between PlayerDataManager and BattleServerManager. Perhaps the ServerRpc is not reaching the BattleServerManager, but I can’t pinpoint the exact reason. I’ve already verified:

  • The NetworkObject is correctly set up on all relevant objects.
  • The SendPawsToServerRpc method is properly marked with [ServerRpc].
  • The player prefab is correctly registered in the NetworkManager.

Questions:

  • Why is the SendPawsToServerRpc method not being called in BattleServerManager?
  • Is there anything I can do to ensure the ServerRpc works correctly in this scenario?

BattleSceneManager.cs (4.6 KB)
PlayerDataManager.cs (6.8 KB)

Seems like you attached the wrong script BattleSceneManager rather than BattleServerManager.
Please embed the code in the post, this makes it easier to read. The forum will make long code fragments scrollable.

Possible cause:
Since BattleServerManager object does not have a NetworkObject (according to your description) or if it’s not subclassing NetworkBehaviour the BSM script can’t receive RPCs.

Note: it’s BAD practice already to call an RPC in another script (breaks encapsulation) but if you send a ServerRPC from WITHIN another ServerRPC there’s definitely something wrong here:

    [ServerRpc(RequireOwnership = false)]
    private void UpdatePawsOnServerRpc(string playerName, NetworkPawData[] pawArray, ServerRpcParams rpcParams = default)
    {
        // ... rest omitted

        battleServerManager.SendPawsToServerRpc(playerName, pawArray, NetworkManager.Singleton.LocalClientId);
    }

UpdatePawsOnServerRpc already runs on the server, thus you can call directly the (non-Rpc) method in battleServerManager that deals with updating paws. I can imagine NGO simply filters that call because it makes no sense to send RPCs to the server on the server!

1 Like

Thank you for your response; your tips were very helpful.
I refactored the code to make the BattleServerManager GameObject have the same name as the script to avoid confusion. Additionally, I added a NetworkObject to it.
In the PlayerDataManager, I centralized the ServerRPC calls, which made the game behave as I originally intended in the code.
Thank you once again!

1 Like