Custom Instantiation Data : Send GameObject or Components ?

Options
Hello,
its not possible to send GameObject or Components with this technique ? :
object[] myCustomInitData = GetInitData();
PhotonNetwork.Instantiate("MyPrefabName", new Vector3(0, 0, 0), Quaternion.identity, 0, myCustomInitData);
Receive custom data:
public void OnPhotonInstantiate(PhotonMessageInfo info)
{
    object[] instantiationData = info.photonView.InstantiationData;
    // ...
}
Thank you

Comments

  • Tobias
    Options
    Right. GameObject and Components are not serializable.
    What you can do is create a script for the prefab to enable/disable components or subobjects on demand. Then send a bool[] which ones need to be active.
  • Jimanji
    Options
    Ok thank you, that help me.
  • DbzRock
    Options
    @Tobias how can a make my own object[] myCustomInitData?
    I have to pass some int values to the OnPhotonInstantiate but I can't figure out how to do it.
  • Jimanji
    Jimanji
    edited November 2020
    Options
    @DbzRock
    int number = 12;
    string word = "hello";
    
    object[] myCustomInitData = new object[]
              {
                    number,
                    hello
              };
            PhotonNetwork.Instantiate(Path.Combine("Players", "Player" , transform.position, Quaternion.identity, 0, myCustomInitData);
    
    
    public class RandomCall : MonoBehaviourPun, IPunInstantiateMagicCallback
    {
        public void OnPhotonInstantiate(PhotonMessageInfo info)
        {
            object[] instantiationData = info.photonView.InstantiationData;
    
            int number = (int)instantiationData[0];
            string word = (string)instantiationData[1];
        }
    }