[Netcode] Behaviour index was out of bounds. Did you mess up the order of your NetworkBehaviours?

So I’ve been following some tutorials online and have been trying to create a multiplayer 3D game, and so far, all I want to do is for two clients to be able to connect to a server, spawn their players (spheres), and move their spheres around and into each other, causing collisions.

I have created a player movement script to handle input - just simple WASD and space-jump movement.

To handle the networking, I followed Tarodev’s Netcode video to set everything up.

Here is where the problem begins. Using ParrelSync, I run the game on one editor and a clone on another. I then use a GameObject with the NetworkManager script to start a host on one editor, and a client on the other. Upon connection, the client and host both spawn players, but then the problem begins. As the client’s player starts falling down, the host’s editor starts experiencing errors and warnings. As mentioned in the title, here they are:

[Netcode] Behaviour index was out of bounds. Did you mess up the order of your NetworkBehaviours?

[Netcode] Network variable delta message received for a non-existent behaviour. NetworkObjectId: 2, NetworkBehaviourIndex: 2

I did a bit of digging and found that the error was being thrown by a function in the NetworkObject script, but I couldn’t really understand why or how to fix it, hence this post.

Errors are only thrown on the client when the host moves its player, and errors are only thrown on the host when the client moves its player. The transforms of the players are not being transmitted between host and client at all, despite the player prefab having a Client Network Transform script, and a NetworkObject script.

Here is the link to the code if you want to reproduce the error or understand it better: GitHub - GodlikeGamesLimited/Sumo101

Any help would be appreciated as this error is driving me insane.

I took a look at the code, I wasn’t able to get it running as the scene was empty, but that might have been the way I copied over to a new project.

The issue is likely where you use this line:

 if(!IsOwner) {Destroy(this);}

From what I can see Tarodev is using it to remove the PlayerController component from other player objects leaving the one owned by the client. If you use it to destroy a component that the server needs to communicate with it will result in the above errors. Try commenting them out and see if it makes a difference.

For me : the reason I was having this issue was because I use an “Object Pooler” to spawn NetworkObjects at the beggining and set them incative until need. The crazy part is, I NEVER touched this script and the bug came from there.
I removed junk code from ANOTHER script I called “Spell” that is attached to the NetworkObjects the Object Pooler was spawning. I was doing this in the object pooler :

    GameObject obj = Instantiate(pool.Prefab);
    obj.SetActive(false);
    obj.GetComponent<NetworkObject>().Spawn();

Again, this NEVER changed and worked.

This is what I did after this bug came up on my “Spell” script, which I figured meant the NetworkObject was not initialized correctly for some reason. Even though it always worked … :

    GameObject obj = Instantiate(pool.Prefab);
    obj.GetComponent<NetworkObject>().Spawn();
    obj.SetActive(false);

I just swapped line 2 and line 3 … I guess Spawn needs to come before any changes is made to the NetworkObject but idk…
Hopefully this helps someone, but this is crazy.

1 Like

As cerestorm mentioned, the issue is likely in this line:

if (!IsOwner) Destory(this);

The script may not be deleted dynamically due to netcode internal requirements.So I changed the code and it works.

if (!IsOwner) enabled = false;
6 Likes

thank you all very much i was so confused by this problem - i never could have solved it by myself - thx

1 Like