Skip to content

ServerRPC not executed if called by a server-only instance of the game #2331

Description

@RikuTheFuffs

Description

ServerRPCs are not executed if called by a server-only instance of the game. This creates a difference in how the game behaves when played as Host vs when played as server-only.
As Host mode is convenient for testing quicker, developers might not realize that the server-only version of the game would not work as expected until they release it.
The lack of errors/warnings makes it hard to debug this, causing frustration.

Reproduce Steps

  1. Create a script with this code
public class NonPlayerNetworkedObject : NetworkBehaviour
{
    public override void OnNetworkSpawn()
    {
        if (IsServer)
        {
            Debug.Log("On server and calling serverrpc...");
            MyServerRpc();
        }
    }

    [ServerRpc]
    void MyServerRpc()
    {
        Debug.Log("This is the server rpc");
    }
}
  1. Add it to a non-player, networked GameObject

image

  1. Add the object to the list of spawnable objects in the NetworkManager (NetworkPrefabs)
  2. Start the game as host
  3. Spawn the object
  4. See how both logs appear in the console
  5. Restart the game as server-only
  6. Spawn the object
  7. See how only the log from OnNetworkSpawn is visible (MyServerRpc does not get executed)

Actual Outcome

MyServerRpc is not executed when called by a server-only instance of the game

Expected Outcome

MyServerRpc should be executed when called by a server-only instance of the game. Alternatively, a warning/error log should be printed to warn users about what's happening, so that they can refactor their code to ensure it behaves the same in both circumstances.

Environment

  • OS: Windows
  • Unity Version: 2021.3.12f1
  • Netcode Version: 1.1.0
  • Netcode Commit: n/a (unable to get it as this version of NGO is pulled in as a dependency of com.unity.multiplayer.samples.coop 1.4.1)

Additional Context

Discord discussion [here](https://discord.com/channels/449263083769036810/819614943723913246/1045346065387356200

Metadata

Metadata

Assignees

Labels

type:featureNew feature, request or improvementtype:supportQuestions or other support

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions