How to pass a GameObject to Instantiated Player?

Options
I've been searching for 2 days now, but there really isn't any good documentation on this:

I've got several spawnpoints in a level that consist of a gameobject and a "spawnStats" script that contains several variables. The spawning is working just fine, but after I have photon instantiate the player, I need to pass them the particular GameObject I used so that they can then load the data from the spawnStats script.

I've been looking into the "instanceData" field at the end of PhotonNetwork.Instantiate, which is supposedly supposed to let me send custom data, but I can't find any decent examples of actual code showing how to do this, just inferences. I get the script to the point where unity throws no errors, but when I run it, I get "Exception: cannot serialize(): UnityEngine.GameObject".

The code I spawn with:
public GameObject spawnSpot;

object[] instanceData = new object[1];
instanceData[0] = spawnSpot;
GameObject player = PhotonNetwork.Instantiate(startSpawnStats.player.name, new Vector3(0f, 0f, 0f), Quaternion.identity, 0, instanceData);
And the code on the player:
void OnPhotonInstantiate()
{
        object[] data = photonView.instantiationData;
	mySpawnSpot = (GameObject) data[0];
}
Any ideas on how to do this? I have no idea where else to look.

Comments

  • Hi @gevarre,

    you can not send an entire game object using Photon. Instead please try sending the position of the spawn point and the necessary rotation if this is required.