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

MLAPI Tutorial Help

Discussion in 'Netcode for GameObjects' started by WorldSeed3000, Jun 15, 2021.

  1. WorldSeed3000

    WorldSeed3000

    Joined:
    Dec 14, 2020
    Posts:
    5
    Hey all,
    I am having trouble with the tutorial (Yes, I've tried Googling). I am currently at the end of Part 2 of 3. (Building on "Hello World"). I was wondering if someone could help. Thanks!

    Error: NullReferenceException: Object reference not set to an instance of an object (It is talking about the MLAPI.NetworkManager.StartHost function. Longer log below)

    Relevant Details

    1. As Part 1 (Your First Networked Game "Hello World") instructed, after I finished working on the PlayerPrefab in the Scene, I dragged it into the Assets/Prefabs folder and then deleted it from the scene. But at the beginning of Part 2, I saw in the videos that the PlayerPrefab was in the scene and was confused. So I did all of the Part 2 PlayerPrefab instructions onto the PlayerPrefab in the assets folder and then dragged it into the scene.
    2. I included the following 2 includes at the top of my code. Besides that, all of the scripts are just copy-pasted from the tutorial itself.
      Code (CSharp):
      1. using System.Collections;
      2. using System.Collections.Generic;
    Thanks for your help!




    The error in full:

    NullReferenceException: Object reference not set to an instance of an object
    MLAPI.NetworkManager.StartHost (System.Nullable`1[T] position, System.Nullable`1[T] rotation, System.Nullable`1[T] createPlayerObject, System.Nullable`1[T] prefabHash, System.IO.Stream payloadStream) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkManager.cs:555)
    NetworkManagerEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Editor/NetworkManagerEditor.cs:371)
    UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at /Users/bokken/buildslave/unity/build/External/MirroredPackageSources/com.unity.ui/Editor/Inspector/InspectorElement.cs:546)
    UnityEngine.GUIUtility: ProcessEvent(Int32, IntPtr, Boolean&) (at /Users/bokken/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:189)
     
  2. WorldSeed3000

    WorldSeed3000

    Joined:
    Dec 14, 2020
    Posts:
    5
    Solution: After you drag the PlayerPrefab into the Network Manager (specifically, into the NetworkPrefabs field), you need to mark it as "Default Player Prefab".
     
    gracetonero likes this.
  3. gracetonero

    gracetonero

    Joined:
    Jul 11, 2021
    Posts:
    1
    Thank you helped me out as well!