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: https://github.com/XR101/Sumo101
Any help would be appreciated as this error is driving me insane.
CodePudding user response:
It seems to me like this could be an error in the order of components on your game objects.
If there's only one component on each object, then make sure you're instantiating them correctly on the server via NetworkServer.Spawn
If you're sure you've done those things, then it's probably a component mismatch due to PlayerMovement
and PlayerMovement2
being used. I have zero experience with Unity's networking stuff but it seems from the docs that they're intended to communicate with a NetworkBehaviour
of the same type.