- Home /
Why is NetworKserver.Spawn() creating a Spawn button in NetworkIdentity?
Why is NetworKserver.Spawn() creating a Spawn button in NetworkIdentity?
When I try to spawn a new obj by using a method like:
[Command]
void CmdSpawn {
NetworkServer.Spawn(newGameObject);
}
A "spawn"-button is created in network identity and the object I am trying to spawn does not appear local nor on other clients before i click the "spawn"-button in the network identity.
How can I make the object spawn directly without having to click the "spawn"-button?
I instantiated the object, but the objects appears on server but not on the other client, and NetworkIdentity shows "spawn" button.
public void SpawnObj(GameObject g,Vector3 pos,Quaternion q){
GameObject g1 = (GameObject)Instantiate (g, pos, q);
NetworkServer.Spawn (g1);
}
Answer by KaldrisRelm · Sep 07, 2015 at 06:28 AM
You need to Instantiate the object first before you can spawn it, try the below:
[Command]
void CmdSpawn
{
GameObject NewObject = (GameObject)Instantiate (newGameObject, transform.position, transform.rotation);
NetworkServer.Spawn(NewObject);
}
Answer by Eco-Editor · Aug 16, 2017 at 07:30 AM
Same issue here.. This line of code is giving me errors...
it says: Attribute command is not valid on this deceleration type. it is only valid on method declarations
or on the CmdSpawn it says:
property or indexes must have at least one accessor / cannot have void type
Your answer
![](https://koobas.hobune.stream/wayback/20220612020348im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Network client : cannot fire 0 Answers
UNET Network.Spawn and child objects 1 Answer
How to network spawn an object from a downloaded asset bundle 0 Answers