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

UnassignedReferenceException: The variable m_PlayerPrefab of LobbyManager has not been assigned.

Discussion in 'Multiplayer' started by cihand3, Jul 13, 2017.

  1. cihand3

    cihand3

    Joined:
    Oct 10, 2012
    Posts:
    3
    Hi everyone,

    I override OnServerAddPlayer method in LobbyManager class. But unfortunately it gives me an error in the inspector : UnassignedReferenceException: The variable m_PlayerPrefab of LobbyManager has not been assigned.

    I use 5.6.2.f1 and Network Lobby 1.7 (the latest).

    My player prefab is already assigned. Do you have any idea about how to solve this?

    Thanks in advance,

    THE CODE in LobbyManager.cs

    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
    var spawnPosition = Vector3.right * conn.connectionId;
    var player = GameObject.Instantiate(playerPrefab, spawnPosition, Quaternion.identity) as GameObject;
    NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);

    #if UNITY_5_1 || UNITY_5_2
    // The new connection isn't active yet so check against 0 connections to determine if the server just started and objects can spawn.
    if (NetworkServer.connections.Count == 0) {
    EventHandler.ExecuteEvent("OnNetworkAddFirstPlayer");
    }
    #else
    if (NetworkServer.connections.Count == 1) {
    EventHandler.ExecuteEvent("OnNetworkAddFirstPlayer");
    }
    #endif

    THE ERROR i see in inspector


    UnassignedReferenceException: The variable m_PlayerPrefab of LobbyManager has not been assigned.
    You probably need to assign the m_PlayerPrefab variable of the LobbyManager script in the inspector.
    UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/UnityEngineObjectBindings.gen.cs:53)
    UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:156)
    UnityEngine.Object.Instantiate[GameObject] (UnityEngine.GameObject original, Vector3 position, Quaternion rotation) (at /Users/builduser/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:206)
    Prototype.NetworkLobby.LobbyManager.OnServerAddPlayer (UnityEngine.Networking.NetworkConnection conn, Int16 playerControllerId) (at Assets/Lobby/Scripts/Lobby/LobbyManager.cs:74)
    UnityEngine.Networking.NetworkManager.OnServerAddPlayerMessageInternal (UnityEngine.Networking.NetworkMessage netMsg) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkManager.cs:873)
    UnityEngine.Networking.NetworkConnection.InvokeHandler (Int16 msgType, UnityEngine.Networking.NetworkReader reader, Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkConnection.cs:220)
    UnityEngine.Networking.NetworkServer.InvokeHandlerOnServer (UnityEngine.Networking.ULocalConnectionToServer conn, Int16 msgType, UnityEngine.Networking.MessageBase msg, Int32 channelId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1654)
    UnityEngine.Networking.ULocalConnectionToServer.Send (Int16 msgType, UnityEngine.Networking.MessageBase msg) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/LocalConnections.cs:83)
    UnityEngine.Networking.ClientScene.AddPlayer (UnityEngine.Networking.NetworkConnection readyConn, Int16 playerControllerId, UnityEngine.Networking.MessageBase extraMessage) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:200)
    UnityEngine.Networking.ClientScene.AddPlayer (UnityEngine.Networking.NetworkConnection readyConn, Int16 playerControllerId) (at /Users/builduser/buildslave/unity/build/Extensions/Networking/Runtime/ClientScene.cs:133)
    UnityEngine.Networking
     
    Last edited: Jul 13, 2017
  2. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,292
    You're missing Player prefab attached to your custom LobbyManager in the inspector. You need to either specify it manually or change playerPrefab variable via code.
     
  3. cihand3

    cihand3

    Joined:
    Oct 10, 2012
    Posts:
    3
    No, it's already assigned in the inspector as i said in my previous message.
     

    Attached Files:

    • 1.png
      1.png
      File size:
      694.2 KB
      Views:
      1,039
  4. tribio

    tribio

    Joined:
    Oct 5, 2013
    Posts:
    29
    the same issue here....have you found a solution?
     
  5. namindu1

    namindu1

    Joined:
    Nov 21, 2019
    Posts:
    1
    I created a new public variable for player prefab and used it.