Search Unity

Question Long string

Discussion in 'Netcode for GameObjects' started by lavagoatGG, Feb 7, 2023.

  1. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Hello,
    I noticed that in order to make a string network variable I need to ude fixed string. I am planning to use very long strings in my game and the longest fixed string I found was 4096 bytes. Is there a longer fixed string or another solution?
     
  2. Deleted User

    Deleted User

    Guest

    Can you use
    NativeText
    ? There's a reason the largest stack allocated strings are 4096 bytes -- going much above that carelessly and you start approaching stack overflow and performance degradation issues.

    UPDATE:
    I see now, referencing this part in the documentation: https://docs-multiplayer.unity3d.co...nced-topics/serialization/serialization-intro.

    Can you use just the primitive
    System.String
    (
    string
    ) type? Or you can add your own serialization logic: https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/custom-serialization
     
    Last edited by a moderator: Feb 7, 2023
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,892
    Yeah I would go for custom serialization of the type and maybe also add packing the data. If it's a Json string for example then packing (zipping) it will save a lot of traffic.
     
    RikuTheFuffs likes this.