Search Unity

Question Cannot synchronize networkbehaviour class at the start of the game

Discussion in 'Netcode for GameObjects' started by miccalisto, Apr 21, 2023.

  1. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    I add a class based on a type of a tile and this class inherits from networkbehaviour. I do this at the start of the game, however I get this error "NetworkBehaviours must be the same, and in the same order, between server and client.". The object is created only on the server and then synchronized to all clients and when using monobehaviour it works all right without any addtional code or setup. But how do I synchronize the networkbehaviour class?
     
  2. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    when I removed the networkvariable I try to synchronize it worked normally, but with the network variable it breaks like this. I tried everything to synchronize it and nothing works I don't know what to do. How do you synchronize the variable without the error?
     
  3. miccalisto

    miccalisto

    Joined:
    Feb 20, 2018
    Posts:
    40
    I found out it's because the added classes is not for somereason synchronized with the clients, so it wouldn't show in clients. How do I synchronized the class added via code to the gameobject?
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,975
    Without seeing any code we‘d have to guess. My best guess is that you do not properly spawn the behaviour/gamebject as stated in the NGO manual. When you say „created only on the server“ this is indicating that you are not considering that every network object exists and must exist for everyone (server/host and clients). To do so you must use the spawn methods of NetworkManager and you can only spawn prefabs, never instantiate or AddComponent. Also prefabs must be registered with the NetworkManager. See the manual on spawning.