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

Resolved Can't change the value of NetworkVariable<FixedString32Bytes>

Discussion in 'Netcode for GameObjects' started by Stanley_DBI, Aug 23, 2023.

  1. Stanley_DBI

    Stanley_DBI

    Joined:
    Feb 18, 2022
    Posts:
    17
    Code (CSharp):
    1. public NetworkVariable<FixedString32Bytes> TestString => new();
    2.  
    3. private void Start()
    4. {
    5.      Debug.Log(TestString.Value.Value == string.Empty);
    6.  
    7.      TestString.Value = new FixedString32Bytes("test");
    8. }
    So, I have this code above in my project to try changing string network variable. It returns true when I tried to compare the property value with string.Empty which means the value is not null, but when I tried to modify it on the next line and it returns NullReferenceException error.

    I'm using Unity 2022.3.3f1 and NGO 1.5.2. Any help would be appreciated.
     
    Last edited: Aug 23, 2023
  2. Stanley_DBI

    Stanley_DBI

    Joined:
    Feb 18, 2022
    Posts:
    17
    Code (CSharp):
    1. public NetworkVariable<FixedString32Bytes> TestString {get; private set;} = new();
    2. private void Start()
    3. {
    4.      Debug.Log(TestString.Value.Value == string.Empty);
    5.      TestString.Value = new FixedString32Bytes("test");
    6. }
    My bad. Changing the property to have a getter and setter fixed the issue.