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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question "[MLAPI] Var data read too far. 1 bytes." When spawning client player prefab

Discussion in 'Netcode for GameObjects' started by dustyh55, Apr 11, 2021.

  1. dustyh55

    dustyh55

    Joined:
    Dec 10, 2013
    Posts:
    3
    When joining a server, the client will spawn the player prefab from other players, but will not spawn it's own prefab.

    I get

    [MLAPI] Var data read too far. 1 bytes.

    [MLAPI] Var data read too little. 15 bytes.

    [MLAPI] Failed to create object locally. [PrefabHash=0]. Hash could not be found. Is the prefab registered?

    So it seems the data stream is getting messed up somehow, but how? I tested a simpler player prefab and it spawned fine, what cold I have possibly done to the prefab to get this kind of behaviour?

    Full errors:


    [MLAPI] Var data read too far. 1 bytes.
    UnityEngine.Debug:LogWarning(Object)
    MLAPI.Logging.NetworkLog:LogWarning(String)
    MLAPI.NetworkedBehaviour:SetNetworkedVarData(List`1, Stream)
    MLAPI.NetworkedObject:SetNetworkedVarData(Stream)
    MLAPI.Spawning.SpawnManager:SpawnNetworkedObjectLocally(NetworkedObject, UInt64, Boolean, Boolean, Nullable`1, Stream, Boolean, Int32, Boolean, Boolean)
    MLAPI.Messaging.InternalMessageHandler:<HandleConnectionApproved>g__DelayedSpawnAction|4_0(Stream)
    MLAPI.Messaging.InternalMessageHandler:HandleConnectionApproved(UInt64, Stream, Single)
    MLAPI.NetworkingManager:HandleIncomingData(UInt64, String, ArraySegment`1, Single, Boolean)
    MLAPI.NetworkingManager:HandleRawTransportPoll(NetEventType, UInt64, String, ArraySegment`1, Single)
    MLAPI.NetworkingManager:Update()


    [MLAPI] Var data read too little. 15 bytes.
    UnityEngine.Debug:LogWarning(Object)
    MLAPI.Logging.NetworkLog:LogWarning(String)
    MLAPI.NetworkedBehaviour:SetNetworkedVarData(List`1, Stream)
    MLAPI.NetworkedObject:SetNetworkedVarData(Stream)
    MLAPI.Spawning.SpawnManager:SpawnNetworkedObjectLocally(NetworkedObject, UInt64, Boolean, Boolean, Nullable`1, Stream, Boolean, Int32, Boolean, Boolean)
    MLAPI.Messaging.InternalMessageHandler:<HandleConnectionApproved>g__DelayedSpawnAction|4_0(Stream)
    MLAPI.Messaging.InternalMessageHandler:HandleConnectionApproved(UInt64, Stream, Single)
    MLAPI.NetworkingManager:HandleIncomingData(UInt64, String, ArraySegment`1, Single, Boolean)
    MLAPI.NetworkingManager:HandleRawTransportPoll(NetEventType, UInt64, String, ArraySegment`1, Single)
    MLAPI.NetworkingManager:Update()


    [MLAPI] Failed to create object locally. [PrefabHash=0]. Hash could not be found. Is the prefab registered?
    UnityEngine.Debug:LogError(Object)
    MLAPI.Logging.NetworkLog:LogError(String)
    MLAPI.Spawning.SpawnManager:CreateLocalNetworkedObject(Boolean, UInt64, UInt64, Nullable`1, Nullable`1, Nullable`1)
    MLAPI.Messaging.InternalMessageHandler:<HandleConnectionApproved>g__DelayedSpawnAction|4_0(Stream)
    MLAPI.Messaging.InternalMessageHandler:HandleConnectionApproved(UInt64, Stream, Single)
    MLAPI.NetworkingManager:HandleIncomingData(UInt64, String, ArraySegment`1, Single, Boolean)
    MLAPI.NetworkingManager:HandleRawTransportPoll(NetEventType, UInt64, String, ArraySegment`1, Single)
    MLAPI.NetworkingManager:Update()
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    How many and what type of NetworkVariables do you have on your player prefab? If you are using a custom INetworkSerialiazable that could be causing issues like that if there is a mistake in your serialization code.

    Besides that the only thing which comes to mind which could be causing this is a rare race condition we found which corrupts the data stream on the client while deserializing.
     
    dustyh55 likes this.
  3. dustyh55

    dustyh55

    Joined:
    Dec 10, 2013
    Posts:
    3
    Thank for the reply!

    Turns out I had make some NetworkedArrays of a custom INetworkSerialiazable class for testing purposes and removing those fixed the problem. It's weird though because the problem started happening long after I had created them (an update maybe?), anyway it's fixed, thanks for the suggestions.