Send and Receive Custom Initiation Data

I'm trying to send and receive a string and int on some Custom Initiation Data, but I can't seem to either send or receive either one. I have been trying for hours now but no luck, please help:

Send Script:


  1. public string snakeName;
  2.  
  3.  
  4. public float minZ;
  5.  
  6.  
  7. void Start()
  8.    {
  9.  
  10.  
  11.     snakeName = PlayerPrefs.GetString("urName");
  12.  
  13.  
  14.      object[] myCustomInitData = new object[]
  15.  
  16.      {
  17.  
  18.       minZ,
  19.  
  20.       snakeName
  21.  
  22.      };
  23.  
  24.  
  25.     PhotonNetwork.Instantiate(playerPrefab.name, randomPoiition, Quaternion.identity, 0, myCustomInitData);
  26.  
  27.  }


Receive Script:


  1. private PhotonView view;
  2.  
  3.  
  4.    public int id;
  5.  
  6.  
  7.    public string snakeName;
  8.  
  9.  
  10.    public void OnPhotonInstantiate(PhotonMessageInfo info)
  11.  
  12.    {
  13.  
  14.      object[] instantiationData = info.photonView.InstantiationData;
  15.  
  16.     id = (int)instantiationData[0];
  17.  
  18.     snakeName = (string)instantiationData[1];
  19.  
  20.  
  21.  
  22.      this.gameObject.name = snakeName;
  23.  
  24.    }


Answers

  • I have to say: "No luck" is not a suitable error description to help you with.

    You defined float minZ for sending but int id for reading this.

    I don't think you need to sync the object name. The relevant ID for networking purposes is the PhotonView.ViewID, not the name of the object. For everything else, the name is just visible in the hierarchy and not really useful.