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. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    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

NetworkVariable/Int/String etc

Discussion in 'Multiplayer' started by cerestorm, Nov 10, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    300
    I'm just trying out Netcode for the first time and I'm struggling with network variables. I see references to NetworkVariableInt etc but can't declare them, have these been removed?

    I was going to check the release notes but the link in the sticky is broken.
     
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    NetworkVariableInt etc. no longer exist. You can use NetworkVariable<int> now etc. For string you have to use NetworkVariable<FixedString64>. Which sticky thread contains the broken links?
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    300
    luke-unity likes this.
  4. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    306
    Thanks, there is already a PR up to fix the documentation page. So hopefully the page will be updated soon with the updated information.
     
    cerestorm likes this.
  5. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    116
    Hi, I just wanted to say that the documentation (as far as I can tell) is still outdated, and it makes working with MLAPI quite tough... Has there been change to use string network variables by the way ? "NetworkVariable<FixedString64>" doesn't seem to work anymore.

    Thank you !
     
  6. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    300
    Having the documentation up to date and accurate should be a priority, it's been almost two months and this isn't the only page that needs correcting.

    Try using FixedString64Bytes, I've been using that without any problems.
     
  7. VincentAbert

    VincentAbert

    Joined:
    May 2, 2020
    Posts:
    116
    Thanks a lot ! One thing I missed was the need for the collections package...
     
  8. Brach_Unity

    Brach_Unity

    Unity Technologies

    Joined:
    May 19, 2021
    Posts:
    7
    We are working on it. We had a full release and are now doing some remedial work catching the final changes and pages that need updated. It will be our main focus now so we are hoping to have the pages all sorted by the end of Jan/Mid-Feb
     
  9. Mandra

    Mandra

    Joined:
    May 15, 2016
    Posts:
    3
    Hello,

    Even though the documentation about network variables exists, I still couldn't find the information about which types are valid.

    If @cerestorm didn't make his comment I would never have found how to use FixedString64Bytes instead of string.

    Could you maybe try and update it, because it's a fairly important information? Thanks!
     
  10. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    300
    Mandra likes this.
  11. Mid_plays

    Mid_plays

    Joined:
    Jan 26, 2022
    Posts:
    7
    And also please how do I convert from a regular int to a network variable of type int
     
  12. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    300
    Use .Value to read and write to a network variable.

    It's useful to have the getter/setter access it that way directly.

    Code (CSharp):
    1. NetworkVariable<int> moveCost = new NetworkVariable<int>();
    2. .
    3. .
    4. public int MoveCost { get => moveCost.Value; set => moveCost.Value = value; }
     
  13. Mid_plays

    Mid_plays

    Joined:
    Jan 26, 2022
    Posts:
    7
    Abdulhamid mamman sule

    Jul 31, 2022, 02:51 UTC

    can someone help me out I keep trying to connect my client to and host but unity keeps sending me this error message, it used to work perfectly normal before I updated the netcode for gameobjects package
    But now the client is not being instantiated I've tried both the pooled and non pooled Spawn system in the documentation and noting works
    Netcode] Deferred messages were received for a trigger of type OnSpawn with key 2, but that trigger was not received within within 1 second(s). UnityEngine.Debug:LogWarning (object) Unity.Netcode.NetworkLog:LogWarning (string) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtime/Logging/NetworkLog.cs:28) Unity.Netcode.DeferredMessageManager:purgeTrigger (Unity.Netcode.IDeferredMessageManager/TriggerType,ulong,Unity.Netcode.DeferredMessageManager/TriggerInfo) (at Library/PackageCache/com.unity.netcode.gameobjects@1.0.0/Runtim
     
unityunity