Skip to content

NullReferenceException in NetworkConnectionManager.cs when PlayerPrefab is not assigned #3964

@Ceeeeed

Description

@Ceeeeed

In NGO version 2.11.1, a NullReferenceException is thrown in NetworkConnectionManager.cs at line 975 when PlayerPrefab is not assigned in the inspector.

Current code:

var idHashToSpawn = playerPrefabHash ?? NetworkManager.NetworkConfig.PlayerPrefab?.GetComponent<NetworkObject>()?.GlobalObjectIdHash;

Changing the code to the following fixes the issue:

var idHashToSpawn = playerPrefabHash;

var playerPrefab = NetworkManager.NetworkConfig.PlayerPrefab;
if (idHashToSpawn == null && playerPrefab != null && playerPrefab.TryGetComponent<NetworkObject>(out var playerNetworkObject))
    idHashToSpawn = playerNetworkObject.GlobalObjectIdHash;

After this change, everything works correctly even when PlayerPrefab is not assigned.

The exception occurs after calling:

NetworkManager.StartHost();

while using SinglePlayerTransport.

Environment:

  • NGO version: 2.11.1
  • Transport: SinglePlayerTransport
  • Unity version: 6000.3.11.f1

Metadata

Metadata

Assignees

No one assigned

    Labels

    stat:awaiting-triageStatus - Awaiting triage from the Netcode team.stat:reply-neededAwaiting reply from Unity accounttype:bugBug Report

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions