- Home /
 
               Question by 
               White8eard · Sep 29, 2015 at 09:10 AM · 
                c#gameobjectnetworkinginstantiatespawn  
              
 
              How to spawn gameobject from host to all clients
i want a object to spawn every few sec,on all my clients, i have a gameobject in which i have attacted this script and added network identity. (unticked both) and the spawning object has network identiy (both unticked) aswell as registered to network manager.but everytime it spawns i get following error.
 NullReferenceException: Object reference not set to an instance of an object
 UnityEngine.Networking.NetworkServer.GetNetworkIdentity (UnityEngine.GameObject go, UnityEngine.Networking.NetworkIdentity& view) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1096)
 UnityEngine.Networking.NetworkServer.SpawnObject (UnityEngine.GameObject obj) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1302)
 UnityEngine.Networking.NetworkServer.Spawn (UnityEngine.GameObject obj) (at C:/buildslave/unity/build/Extensions/Networking/Runtime/NetworkServer.cs:1531)
 SpawnControl.SpeedSpawn () (at Assets/Scripts/SpawnControl.cs:49)
 SpawnControl.CreateSpeed () (at Assets/Scripts/SpawnControl.cs:37)
 SpawnControl.Update () (at Assets/Scripts/SpawnControl.cs:28)
 
     // Update is called once per frame
     void Update()
     {
         if(isServer)
         {
            CreateSpeed();
         }
     }
 
     public void CreateSpeed()
     {
         if (SpeedBoost < 0)
         {
             SpeedBoost = 7;  
             SpeedSpawn();
         }
         else
         {
             SpeedBoost -= Time.deltaTime;
         }
     }
 
     public void SpeedSpawn()
     {
         int n = Random.Range(0, SpawnPoints.Count);
         GameObject go = Instantiate(SpawnItems[0], SpawnPoints[n].position, Quaternion.identity) as GameObject;
         NetworkServer.Spawn(go);
     }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by White8eard · Sep 29, 2015 at 11:59 AM
Fixed it. I changed Public Transfform[] SpawnItems; to Public GameObject[] SpawnItems;
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                