How do I keep track of projectile owners in a networked game?

I’ve got a networked multiplayer game going using the M2H examples as the starting point. Everything is working fine except that I have to use instantiated projectiles instead of raycasting (they are slow-moving missiles and things), so I’m trying to figure out how to determine which player fired the projectile that hits another player.

I’ve tried setting variables on scripts on the projectiles and everything else I can think of, but nothing seems to work. The method that’s gotten me the closest is to have the player that fires the projectile rename it. Then the player it hits can use OnCollisionEnter(hit : Collision) to read the name and do the appropriate calculations.

I currently have this in a script on the player firing the projectile:

 var projectile : Transform;

 function FireMissile () {
      var missile = Network.Instantiate(projectile, launcher.position, launcher.rotation, 0);
 missile.name = "myFancyMissile";
 }

Unfortunately, this works great, but only for the player that is also the server. None of the other players’ missile names change and I can’t figure out why. I’ve got a network view and so on on the prefab, and they work just fine otherwise. They just don’t get the name change.

I’m not tied to this approach. It’s just the one that’s gotten me the closest, so I’m open to other suggestions.

Let’s try a few approaches. First, try putting the entire rpc call on the missile, i.e:

function Awake()
{
	networkView.RPC("ChangeMissileName", RPCMode.All, shooterName);
}

@RPC 
function ChangeMissileName(myMissile : String)
{ 
	this.name = myMissile;
}

If that doesn’t work, try instantiating the missile in an rpc instead of Network.Instantiate (player script):

var missileViewId = Network.AllocateViewID();
networkView.RPC("FireMissile", RPCMode.AllBuffered, missileViewId, missileName);
    
@rpc
function FireMissile(mName : string, viewId : NetworkViewID)
{
	var missile = Instantiate(projectile, launcher.position, launcher.rotation) as Transform;
	var nView : NetworkView;
	nView = missile.GetComponent(NetworkView);
	nView.viewID = viewID;
  	missile.name = mName;
}

Naturally you’ll want to separate missile fire and missile death RPC’s to different network groups for better management through networkView.group too