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. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Question Nullable types for NetworkList/NetworkVariable

Discussion in 'Netcode for GameObjects' started by XeLLLeR, Apr 19, 2022.

  1. XeLLLeR

    XeLLLeR

    Joined:
    Dec 5, 2020
    Posts:
    30
    So I have a struct with string field inside. Because of this I get a compile error:
    Code (CSharp):
    1. The type 'MyStruct' must be valid unmanaged type (simple numeric, 'bool', 'char', 'void', enumeration type or struct with all fields of unmanaged types at any level of  nesting) in order to use it as a type argument for 'T' parameter
    As you know NetworkList and NetworkVariable is generic types, so I can't use nullable types here (in my case it's a string)
    Also nullable types unavailable for NetworkVariable.
    Is it possible to use nullable types for this two classes somehow?
    P.S. Looks like FixedString64 is the way to go, but my IDE doesn't see this struct so I can't implement this in code. I tried using Unity.Collections, but it has not worked.
    P.S.2 I just forgot about assembly definition. Added Unity.Collections into it and now everything works!
     
    Last edited: Apr 19, 2022
    CasualT_Bossfight likes this.
  2. Horst6667

    Horst6667

    Joined:
    Feb 5, 2018
    Posts:
    12
    With Netcode 1.0.0-pre8 FixedString64Bytes ceased to work too.
    It now raises a runtime error:

    Exception: Type Unity.Collections.FixedString64Bytes is not serializable - it must implement either INetworkSerializable or ISerializeByMemcpy

    So at the moment we cannot use NetworkVariable<string> neither NetworkVariable<FixedString64Bytes>

    Send help. :)
     
    Tymek_1200, lavagoatGG and Stealcase like this.
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    402
    This is a problem for me as well, in case it's missed here I raised an issue on GitHub.
     
  4. Stealcase

    Stealcase

    Joined:
    Feb 26, 2018
    Posts:
    9
    Yup, this broke my game as well.
    Im now trying to wrap my FixedString*Byte inside ForceNetworkSerializeByMemcpy<T>.

    Code (CSharp):
    1. struct MyObject
    2. {
    3.     public ForceNetworkSerializeByMemcpy<FixedString64Bytes> RandomString;
    4. }

    I'll let you know how it goes.
     
  5. hoesterey

    hoesterey

    Joined:
    Mar 19, 2010
    Posts:
    659
    Did this end up working? I'm not a fan of how some information is hidden on git now. Unity is starting to feel more and more like an open source product.
     
  6. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Using ForceNetworkSerializeByMemcpy<FixedString64Bytes> is currently the way to go starting from this release. We're looking at bringing back the old behaviour which allowed for just using fixed string on its own.
     
    lavagoatGG likes this.