NetworkBehaviours cannot use commands from parent classes

Commands in NetworkBehaviours cannot be used in subclasses of those NetworkBehaviours. Here’s an example:

Given this baseic NetworkBehaviour:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class CmdTest : NetworkBehaviour {

    protected void Test() {
        if (!isServer) {
            CmdCmdTest();
        }
    }

    [Command]
    void CmdCmdTest() {
        Debug.Log("CmdTest!");
    }

}

and this subclass:

using UnityEngine;
using System.Collections;
using UnityEngine.Networking;

public class AdvCmdTest : CmdTest {

    void Update() {
        Test();
        AdvTest();
    }

    void AdvTest() {
        if (!isServer) {
            CmdAdvTest();
        }
    }

    [Command]
    void CmdAdvTest() {
        Debug.Log("AdvTest");
    }
}

Calling the command in the base class results in a “Found no receiver” message, but the command directly in the subclass executes properly:

Found no receiver for incoming command [Command:InvokeCmdCmdCmdTest] on Player(Clone) (UnityEngine.GameObject),  the server and client should have the same NetworkBehaviour instances [netId=13].
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
AdvTest
UnityEngine.Debug:Log(Object)
AdvCmdTest:CmdAdvTest() (at Assets/_Shooter/Scripts/AdvCmdTest.cs:24)
AdvCmdTest:InvokeCmdCmdAdvTest(NetworkBehaviour, NetworkReader)
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Bug 693939 was filed for this.

This appears to be resolved (Commands get invoked from subclasses), however I’m now seeing an error in the log for each other network aware component on the server’s instance of the GameObject when the command gets called from a remote client.

Sample output for above code with other components on GameObject:

InvokeCommand class [NetworkTransform] doesn't match [CmdTest])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

InvokeCommand class [NetworkTransformVisualizer] doesn't match [CmdTest])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

InvokeCommand class [NetworkTransform] doesn't match [AdvCmdTest])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

InvokeCommand class [NetworkTransformVisualizer] doesn't match [AdvCmdTest])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

Additionally, the ClientRpcs have a similar problem to the initial behaviour regarding commands - attempting to execute a ClientRpc from a base class results in a message like the following:

Failed to invoke RPC ClientRpc:CmdTest:InvokeRpcRpcBase(-284462125) on netID 2
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
1 Like

That will happen if you have both CmdTest and AdvTest components (child and parent classes) on the same object. To the system, that is the same as having two instances of the same NetworkBehaviour on the object - and that is not supported.

I don’t have both components on the object. Just AdvTest. The errors are complaining about the other components (network transform etc) not matching CmdTest or AdvTest. The reason both are being matched is because AdvTest is using a command from its parent class, CmdTest.

I just wanted to add that I am also hitting this bug. I have only added the child class to the GameObject. Case 697682 was filed for this

I’m not even using a child class and I’m getting errors like these in the editor.

InvokeCommand class [Player_PositionSync] doesn't match [Player_NewSynRotation])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

InvokeCommand class [Player_Id] doesn't match [Player_NewSynRotation])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

InvokeCommand class [Player_Health] doesn't match [Player_NewSynRotation])
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

If I host a game in the editor then I get these messages from the remote client. If I host the game from a standalone build I can connect as a remote client seemingly without any problems. I’m seeing these messages in the 5.1.0f2 build but I don’t see them in the 5.1.0b5 build.

It seems that only one script can derive from NetworkBehaviour on a GameObject. It must also sit above any other scripts on that GameObject and those other scripts must be deactivated. I need to get around to submitting a bug report.

Bug report case 699269

This error message is a bug (696680), the commands still work. The bug is fixed in the first patch release for 5.1.

Out of curiosity, when should we actually see that kind of error? People have been asking me about it and I’ve been telling them to ignore it for now.

when that bug is fixed, the only times you would see that error would be when you have mismatching code between a client and server, or when you remove NetworkBehaviour components from objects at runtime.

1 Like