Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only. On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live. Read our full announcement for more information and let us know if you have any questions.

Resolved How would I fix "Unity.Netcode" Namespace not apearing after installing Netcode for Gameobjects?

Discussion in 'Netcode for GameObjects' started by wpeoif0, Jun 6, 2023.

  1. wpeoif0

    wpeoif0

    Joined:
    Dec 11, 2022
    Posts:
    3
    Hello! I am reletively new to Unity and I am trying to convert a single-player game into a multi-player game using Netcode for Gameobjects. However, after installing the Netcode for Gameobjects package in the editor (I have tried two versions of the editor "2021.3.16f1" and "2022.3.0f1", and three versions of Netcode for Gameobjects "1.1.0", "1.2.0", and "1.4.0"), I tried to use the "NetworkBehavior" class in my scripts, but when I try and add "using Unity.Netcode" to the top of the script so that I can use that class, it is underlined in red and says that that namespace does not exist.

    I have tried:
    • Looking through the forums, which lead me to attempt to rebuild the project files with Edit>Preferences>External Tools>Git Packages enabled, then I tried again with Registry Packages enabled as well. Neither worked.
    • Adding the .dll file to the References in the Visual Studio Solution Explorer. When I attempted this, I could find the "Unity.Netcode.Editor.dll", "Unity.Netcode.Runtime.dll", "Unity.Netcode.Components.dll", and a few others, but I could not find the plain "Unity.Netcode.dll".
    I am using:
    • Unity Editor version: 2022.3.0f1 (LTS)
    • Microsoft Visual Studio 2022 (v2.0.18 (I think))
    • Netcode for Gameobjects version: 1.4.0

    Any help is usefull, I hope I was clear enough.
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    7,263
    Try inporting Netcode into a new project to see if you have the same issue.

    In any case, one does not manually add using statements anymore these days. The IDE does that for you with a simple action after you wrote a valid statement (such as subclassing NetworkBehaviour) where the Type exists but is just missing the right import in the current file. The IDE should also add the necessary dependencies to the assembly definition file, if any.

    But … I cannot speak for VS. I would expect it to add usings but I would not be surprised that it still lacks essential Unity workflow features such as adding dependencies to asmdefs. If you use an asmdef make sure to add the Netcode dependency manually.
     
    wpeoif0 likes this.
  3. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    Hi @wpeoif0 , that's not how you reference assemblies in Unity (never do that!). The right way to do it is to reference the dll / package in the Assembly Definition File (asmdf) where the script you want to allow to use NGO's features is placed.

    This page has a lot of info and screenshots on the topic, I'd recommend to read it first.

    Does this help?
     
    wpeoif0 likes this.
  4. wpeoif0

    wpeoif0

    Joined:
    Dec 11, 2022
    Posts:
    3
    Thank you! This was very helpfull.
     
    RikuTheFuffs likes this.