Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved NetworkVariable string

Discussion in 'Netcode for GameObjects' started by lavagoatGG, Aug 9, 2022.

  1. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    Hello,
    What is the current way of creating a network variable that is a string and how should you update it's Value?
    How do I declare ForceNetworkSerializeByMemcpy<FixedString64Bytes> network variable?
    Thank you
     
  2. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    111
    private NetworkVariable<FixedString32Bytes> String_ = new NetworkVariable<FixedString32Bytes>();

    String_.Value = "Something";

    Something like that no? If you dont know how to integrate FixedString32Bytes
    using Unity.Collections;
     
  3. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    When I do String.Value += anotherString;
    then I get the following error:
    FixedString64Bytes: Truncation while copying "anotherString".
    Do you know whats wrong?
     
  4. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    111
    I expect you forgot to do a simple if(IsOwner) / if(IsServer) (Depending on your NetworkVariable write settings) pre change. Because that will happen if more than one NetworkObject tries to change the Value
     
  5. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    The variable is changed in a Server RPC function That is called on a spawned networkObject
     
  6. itisMarcii_

    itisMarcii_

    Joined:
    Apr 5, 2022
    Posts:
    111
    Could you present your code fragment? Right now i am just guessing in the dark :)
     
    CheeseFriz likes this.
  7. lavagoatGG

    lavagoatGG

    Joined:
    Apr 16, 2022
    Posts:
    229
    I think I found the problem. It gives the error only if the string exceeds 64 characters... I will try to use a longer fixedString