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. Dismiss Notice

FixedString32Bytes not serializable after NetworkString implementation

Discussion in 'Multiplayer' started by NEOMORPH_STUDIO_SRL, May 31, 2022.

  1. NEOMORPH_STUDIO_SRL

    NEOMORPH_STUDIO_SRL

    Joined:
    Jan 5, 2016
    Posts:
    12
    We are working with Unity Netcode for Gameobjects version 1.0.0-pre.9 and despite having implemented the INetworkSerializable for FixedString32Bytes, we are still experiencing this error.

    -----------------------------------------------------------------------------------------------
    Code (CSharp):
    1. Exception: Type Unity.Collections.FixedString32Bytes is not serializable - it must implement either INetworkSerializable or ISerializeByMemcpy
    2. Unity.Netcode.NetworkVariableSerialization`1[T].WriteValue[TForMethod] (Unity.Netcode.FastBufferWriter writer, TForMethod& value) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/NetworkVariable/NetworkVariableSerialization.cs:92)
    3. Unity.Netcode.NetworkVariableSerialization`1[T].Write (Unity.Netcode.FastBufferWriter writer, T& value) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/NetworkVariable/NetworkVariableSerialization.cs:144)
    4. Unity.Netcode.NetworkVariable`1[T].WriteField (Unity.Netcode.FastBufferWriter writer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/NetworkVariable/NetworkVariable.cs:124)
    5. Unity.Netcode.NetworkVariable`1[T].WriteDelta (Unity.Netcode.FastBufferWriter writer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/NetworkVariable/NetworkVariable.cs:89)
    6. Unity.Netcode.NetworkVariableDeltaMessage.Serialize (Unity.Netcode.FastBufferWriter writer) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Messaging/Messages/NetworkVariableDeltaMessage.cs:94)
    7. Unity.Netcode.NetworkBehaviour.NetworkVariableUpdate (System.UInt64 targetClientId, System.Int32 behaviourIndex) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkBehaviour.cs:640)
    8. Unity.Netcode.NetworkBehaviour.VariableUpdate (System.UInt64 targetClientId) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkBehaviour.cs:594)
    9. Unity.Netcode.NetworkBehaviourUpdater.NetworkBehaviourUpdate (Unity.Netcode.NetworkManager networkManager) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkBehaviourUpdater.cs:36)
    10. Unity.Netcode.NetworkManager.OnNetworkManagerTick () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkManager.cs:1411)
    11. Unity.Netcode.NetworkTickSystem.UpdateTick (System.Double localTimeSec, System.Double serverTimeSec) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Timing/NetworkTickSystem.cs:96)
    12. Unity.Netcode.NetworkManager.OnNetworkPreUpdate () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkManager.cs:1375)
    13. Unity.Netcode.NetworkManager.NetworkUpdate (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkManager.cs:1322)
    14. Unity.Netcode.NetworkUpdateLoop.RunNetworkUpdateStage (Unity.Netcode.NetworkUpdateStage updateStage) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkUpdateLoop.cs:149)
    15. Unity.Netcode.NetworkUpdateLoop+NetworkPreUpdate+<>c.<CreateLoopSystem>b__0_0 () (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0-pre.9/Runtime/Core/NetworkUpdateLoop.cs:196)
    -----------------------------------------------------------------------------------------------

    This is how we implemented it. Are we doing something wrong or is the problem somewhere else? (We also tried INetworkSerializeByMemcpy, the result is the same)

    Code (CSharp):
    1. public struct NetworkString : INetworkSerializable
    2. {
    3.     private ForceNetworkSerializeByMemcpy<FixedString32Bytes> data;
    4.  
    5.     public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
    6.     {
    7.         serializer.SerializeValue(ref data);
    8.     }
    9.  
    10.     public override string ToString() => data.Value.ToString();
    11.  
    12.     public static implicit operator string(NetworkString networkString) => networkString.ToString();
    13.     public static implicit operator NetworkString(string s) => new NetworkString { data = new FixedString32Bytes(s) };
    14. }
    We took the code from this tutorial (Time is 16:38):

    Anybody has any idea how we can solve this?

    Thanks for your attention!
     
    Last edited: May 31, 2022
  2. NEOMORPH_STUDIO_SRL

    NEOMORPH_STUDIO_SRL

    Joined:
    Jan 5, 2016
    Posts:
    12
    Ok, we finally figured out the problem. Apparently, somewhere in code that was not made from us, someone was still using NetworkVariable<FixedString32Bytes>, so the error is rightfully showing up. The struggle for us was the fact that in no part of the error it was mentioned where the offensive code was (since we are dealing with a generic class), so it took us some time to find it. If you are downloading code or examples from sources that worked with versions prior to pre.7, you should take care for any instance of NetworkVariable<FixedString32Bytes>.