Search Unity

Cannot Spawn object without an active server

Discussion in 'Multiplayer' started by benjaml, Nov 8, 2015.

  1. benjaml

    benjaml

    Joined:
    Feb 18, 2015
    Posts:
    1
    Hi, so I'm trying the new Network system of Unity, and I got some Issues, I can't find a answer on internet, I'm trying to instanciante and Spawn GameObjects but I go this error :

    SpawnObject for Map Manager(Clone) (UnityEngine.GameObject), NetworkServer is not active. Cannot spawn objects without an active server.

    So I don't know why Network server is not active, I got this error when I click on "LAN Host(H)" with the Network Manager HUD,

    I've made this networkManager to instanciate my Managers on the server when the server is started :

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Networking;
    3. using System.Collections;
    4.  
    5. public class NetworkManagerScript : NetworkManager {
    6.  
    7.     public GameObject[] ListToSpawn;
    8.  
    9.     public override void OnStartServer()
    10.     {
    11.         foreach(GameObject obj in ListToSpawn)
    12.             NetworkServer.Spawn(Instantiate(obj)as GameObject);
    13.     }
    14. }
    15.  

    I don't know why I got this error, probably something I'm doing wrong, I hope for a answer

    Thanks :)
     
  2. sanatan

    sanatan

    Joined:
    Nov 14, 2015
    Posts:
    10
    Same problem here. The lack of help on the unity forums is really disgusting. I wonder if the Unreal engine has better support.
     
  3. wstcgez

    wstcgez

    Joined:
    May 21, 2014
    Posts:
    12
    if (!isServer)
    return;
    add this before to spawn. because client can't spawn.
     
    One-Zero likes this.
  4. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
  5. Gaidzin

    Gaidzin

    Joined:
    Nov 14, 2012
    Posts:
    14
    Используйте Coroutine и while (true).
     
  6. Driiades

    Driiades

    Joined:
    Oct 27, 2015
    Posts:
    151
    base.OnStartServer() before your code ? maybe maybe not :)