Network.Instantiate instantiates twice


I’m working on a gun for a multiplayer. When I spawn a projectile the guns spawns it twice this should be just one time. I have a weapon control script:

public void Fire (int myID) {
	foreach (Weapon wp in weapons) {
		wp.Fire (myID);
		Debug.Log (myID);

a weapon script:

public void Fire (int myID) {
	GetComponent<NetworkView>().RPC ("Shoot", RPCMode.AllBuffered, myID);

public void Shoot (int myID) {
	GameObject thisProjectile;
	thisProjectile = (GameObject) Network.Instantiate (projectile, transform.parent.position + offSet, transform.parent.rotation, 2);
	thisProjectile.GetComponent<Projectile>().setProjectile(myID, speed);

and a projectile script:

void Update () { //A quick fix for now
	if (myOwner == 0)
		Destroy (gameObject);

public void setProjectile (int owner, Vector3 speed) {
	myOwner = owner;
	myRigidbody = gameObject.GetComponent<Rigidbody>();
	myRigidbody.AddForce (speed);

there is just one weapon script attached to my player and his children, both the projectiles spawn at the same spot but one doesn’t get assigned an ID and stays 0. I’ve placed a Debug.Log in every void in the chain and nothing get’s called twice. For now I can just destroy the projectiles with the owner 0. but it annoys me that it is spawning twice and I can’t figure out why it does that.

Instantiate does not go inside the RPC Call!!! saying Network.Instantiate is enough. you can state it elsewhere such as update or start. it automatically creates the objects on all the connected machines. no rpc nessisarry.

so looks like your script is sending a rpc to every player. and now every player in your game creates his own copy of bullets for every player !!!

another words, if your game was 4 player, each player would receive 16. interesting concept but I don’t think that’s what you want!

If you’re calling instantiate within an RPC, you just use “Instantiate” instead of “Network.Instantiate.” RPC functions essentially do the same exact thing as Network functions, they are just more customized because you can edit the function. However, depending on what type of server you’re running (Authoritative or non-authoritative) you’ll want to use different RPC modes and such.