Can't spawn network object

39 Views Asked by At

I tried spawning a prefab I made, and I keep getting the following error message: "NotListeningException: NetworkManager is not listening, start a server or host before spawning objects". The prefab IS a network object and is attached to the player objects script called "spawner". The player object prefab is linked to the network manager's Player field.

The Spawner script:

public class Spawner : NetworkBehaviour
{
    private string _playerID;
    public NetworkObject prefab;

    public override void OnNetworkSpawn()
    {
        _playerID = NetworkManager.LocalClientId.ToString();

    }

    private void Update()
    {
        if (Input.anyKey)
        {
            Debug.Log(_playerID);
            prefab.GetComponent<NetworkObject>().Spawn();
        }
    }
}

(https://i.stack.imgur.com/zzWBX.png)

I start a host after entering play mode, and the player prefab gets spawned, so I guess the server should already be started at the time the spawning should happen.

0

There are 0 best solutions below