Search Unity

Misunderstanding how to add MLAPI to existing singleplayer project

Discussion in 'Netcode for GameObjects' started by danb1, Jun 4, 2021.

  1. danb1

    danb1

    Joined:
    Jun 14, 2019
    Posts:
    24
    I have a simple test game I put together (tetris) and I'm trying to add MLAPI to it to make it multiplayer, just to learn how things work. The idea is that when a player joins a server it spawns in an entire tetris board for them, next to the existing player's boards. What I did so far was:
    1. Made a singleplayer version of the game, which just has some background objects, a camera, the tetris pieces, UI, and code to control everything
    2. Bundled all the objects that each client needs to have (background + tetris pieces + camera + UI) into a prefab and marked this as the player prefab
    3. Added the NetworkObject script to all the objects I want sync'd and NetworkTransform to the tetris blocks, since they move during the game. Also made the tetris code NetworkBehaviours
    Everything actually works fine like this when I run in host -- the game works identically to singleplayer. But I have an error that pops up every few seconds:
    [MLAPI] Behaviour index was out of bounds. Did you mess up the order of your NetworkBehaviours?
    UnityEngine.Debug:LogError (object)
    MLAPI.Logging.NetworkLog:LogError (string) (at Library/PackageCache/com.unity.multiplayer.mlapi@0.1.0/Runtime/Logging/NetworkLog.cs:23)

    I assume I've done something wrong with the way I set up my prefab but I can't quite figure it out from the documentation and other examples, since this use case doesn't match up well with the existing demos I've looked at. If anybody knows where this error is coming from I would appreciate any info!
     
  2. danb1

    danb1

    Joined:
    Jun 14, 2019
    Posts:
    24
    Well shouldn't have asked so quickly, this one is really easy... some of my objects with NetworkTransform didn't also have a NetworkObject component. Please ignore!