Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

185
Vistas
Unity Multiplayer MLAPI Could not get NetworkObject for the NetworkBehaviour

For my PlayerController script, I changed inheriting from MonoBehaviour to NetworkBehaviour

public class PlayerController : MonoBehaviour
{

From this, to this:

public class PlayerController : NetworkBehaviour
{

Even though my player controller object does have a NetworkObject component.

Its throwing an error saying that it doesn't have one.

NullReferenceException: Could not get NetworkObject for the NetworkBehaviour. Are you missing a NetworkObject component?
MLAPI.NetworkBehaviour.get_NetworkObject () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkBehaviour.cs:282)
MLAPI.NetworkObject.get_ChildNetworkBehaviours () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkObject.cs:515)
MLAPI.NetworkObject.ResetNetworkStartInvoked () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Core/NetworkObject.cs:472)
MLAPI.Spawning.NetworkSpawnManager.SpawnNetworkObjectLocally (MLAPI.NetworkObject networkObject, System.UInt64 networkId, System.Boolean sceneObject, System.Boolean playerObject, System.Nullable`1[T] ownerClientId, System.IO.Stream dataStream, System.Boolean readPayload, System.Int32 payloadLength, System.Boolean readNetworkVariable, System.Boolean destroyWithScene) (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Runtime/Spawning/NetworkSpawnManager.cs:395)
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:556)
NetworkManagerEditor.OnInspectorGUI () (at Library/PackageCache/com.unity.multiplayer.mlapi@3e3aef6aa0/Editor/NetworkManagerEditor.cs:371)
UnityEditor.UIElements.InspectorElement+<>c__DisplayClass59_0.<CreateIMGUIInspectorFromEditor>b__0 () (at <31768fe99cfe4466aa4a401169fb2ce5>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Its throwing this error as soon as I click on "Start Host" on the Network Manager script/object.

How can I fix this issue?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

For some reason. There was a race condition that made GetComponentInParent return null. So I edited NetworkBehaviour.cs to use GetComponent instead.

    /// <summary>
    /// Gets the NetworkObject that owns this NetworkBehaviour instance
    /// </summary>
    public NetworkObject NetworkObject
    {
        get
        {
            if (m_NetworkObject == null)
            {
                //m_NetworkObject = GetComponentInParent<NetworkObject>();

                m_NetworkObject = GetComponent<NetworkObject>();
            }

            if (m_NetworkObject == null)
            {
                throw new NullReferenceException($"Could not get {nameof(NetworkObject)} for the {nameof(NetworkBehaviour)}. Are you missing a {nameof(NetworkObject)} component?");
            }

            return m_NetworkObject;
        }
    }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda