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:
- 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 aNetworkList
of “Paws” (characters).
- Components:
- BattleServerManager:
- Responsible for server-side logic, such as spawning Paws and coordinating the battle.
- Components:
- Script
BattleServerManager
.
- Script
- Player Prefab:
- Registered in the
NetworkManager
as the player object. - Successfully instantiated in the battle scene (
BattleScene
) when the match starts.
- PlayerLeft and PlayerRight Objects:
- Represent the two sides of the battlefield.
- Both have the
NetworkObject
component.
- Game Flow:
- The match starts, and players are successfully connected.
- The
OnNetworkSpawn
event inPlayerDataManager
is triggered for each player. - Player data (e.g., Paws) is sent from the client to the server via
ServerRpc
.
Logs and Problem:
- Successful Logs:
- The
UpdatePawsOnServerRpc
method inPlayerDataManager
is successfully called. - The log
Notifying the BattleServerManager about the player's Paws SwiftHawk722.
appears on the server.
- Issue:
- The
SendPawsToServerRpc
method inBattleServerManager
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 inBattleServerManager
? - 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)