Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug 2022 LTS, 1.6 NGO. Float Network variable - Specified cast is not valid

Discussion in 'Netcode for GameObjects' started by Unique-Player, Dec 11, 2023.

  1. Unique-Player

    Unique-Player

    Joined:
    May 6, 2017
    Posts:
    79
    Does unity even check what it releases? This issue was known for quite some time, i found thread about it some time ago, and it is still not fixed. How can you take ngo seriously when on release of 1.6 it does not support floats. Wtf.
     
  2. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    285
  3. Unique-Player

    Unique-Player

    Joined:
    May 6, 2017
    Posts:
    79
    No script is needed. Just declare public NetworkVariable float, double or decimal and select an object that has the script. The editor will not draw it in the inspector and throw an error.
    int, for example, will work as expected.
     
  4. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    285
    So, you read over the requirements to use NetworkVariables?

    If I understand you correctly, you are saying that you want to be able to declare the NetworkVariable as public and edit it within the inspector view? Without seeing your script, the errors it is throwing, or the version of NGO you are using I can only provide you with an example of usage.

    Create a component (script file) using the below script:
    Code (CSharp):
    1. using Unity.Netcode;
    2.  
    3. public class MyNetworkVariable : NetworkBehaviour
    4. {
    5.     public NetworkVariable<int> MyIntValue = new NetworkVariable<int>();
    6.     public NetworkVariable<float> MyFloatValue = new NetworkVariable<float>();
    7. }
    8.  
    Create a blank prefab and add a NetworkObject to it.
    Drag and drop the MyNetworkVariable script onto the prefab or add the component, MyNetworkVariable, by name to your newly created prefab with NetworkObject component.
    Open the prefab or select the prefab and you should see something similar to this:
    upload_2023-12-12_17-46-16.png
    It shouldn't throw any errors or the like when viewing the prefab in the inspector view and you should actually see "NetworkVariable" next to each property.

    If you are getting an error using the provided script please do post it here along with the version of NGO you are using so that I can help you with the issue you are experiencing.
     
  5. Unique-Player

    Unique-Player

    Joined:
    May 6, 2017
    Posts:
    79
    Yes, i have read it.
    And yes, your script is throwing errors.
    Unity version - 2022.3.12f1. Netcode For GameObjects - 1.6.0. 1.6.0 is the latest available one.
    bug.png
     
  6. NoelStephens_Unity

    NoelStephens_Unity

    Unity Technologies

    Joined:
    Feb 12, 2022
    Posts:
    285
    Ok,
    So the most recent version of NGO (v1.7.1) I believe has some fixes that could address that issue.
    If you don't want to update your editor to 2022.3.15f1 (which once updated you would see the option to upgrade NGO), then there are two ways to update to the most recent version manually:

    Packages/Manifest.json

    • Open your manifest.json file and find the com.unity.netcode.gameobjects entry
    • Update the version to 1.7.1 and save the file.
    • The editor should pull down that version of the NGO package.
    Package Manager
    • Open the package manager and select add package by name
    • For the name enter: com.unity.netcode.gameobjects
    • For the version enter: 1.7.1
    • The editor should pull down that version of the NGO package.
    Let me know if this resolves your issue?
    As a side note, you can also visit the Github repository to see what the most current version is in the event you want to update to that manually in the future.