Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

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

Discussion in 'Unity Transport' started by Seforius, Aug 30, 2022.

  1. Seforius


    Jun 25, 2022
    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:

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


    Apr 16, 2020
    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:
    Code (CSharp):
    1.  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.