Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    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.