Fifth parameter of PhotonNetwork.Instantiate?

Options
Hello guys - I got a couple of questions.

First of all let me explain the problem that I'm facing. I set up a basic card game scene. Player meet in a room and every player brings his own deck to the table. Then I'm just instantiating the card template from the resources folder. This template will get its information from a Scriptable Object, which is a public field on the template itself. I am overwriting this field and pass the local data from the player deck to it. I know, that this data is local and bound to the player that called the network instantiation unless I'm loading data from a place that every player in the room has access to. But since I'm not loading "complete objects" from the resources folder, I need to make this data transfer process flexible. I read a bit and found information on the fifth parameter of the Instantiate function where you can pass an array of objects. So for example... I thought about sending a string and let all clients read and use those values at the time of instantiation in order to get specific text onto their screen. However, this is only working for the master client. My question is... why can other clients not access this data correctly? Thanks in advance.. and sorry for grammar and so on, I'm not a native speaker fellas :D

Comments

  • Maurice
    Maurice
    edited April 2020
    Options
    
    object[] cardData = new object["Hello, I'm testing!"];
    
    private void Update()
        {
            if (PV.IsMine)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    GameObject Temp = PhotonNetwork.Instantiate("CardFab",
                        new Vector3(0, 0, 0), Quaternion.identity, 0, cardData);
    
                    PhotonView PV = Temp.GetComponent<PhotonView>();
                    PlayerDeck localDeck = FindObjectOfType<PlayerDeck>().GetComponent<PlayerDeck>();
                    
                    // This initialize function is just synchronizing data to the layout.
                    Temp.GetComponent<CardIdentity>().Initialize(localDeck.CurrentDeck.Content[0], 
                    PV.InstantiationData[0]);
                    
                }
            }
            
        }
    
  • Maurice
    Options
    Guys, I just answered my own question. I am stupid.

    This is the script that is part of the template that I instantiate:
    using Photon.Pun;
    using System.Collections;
    using System.Collections.Generic;
    using TMPro;
    using UnityEngine;
    using UnityEngine.UI;
    
    public class CardIdentity : MonoBehaviour
    {
        public Card Identity;
        public Image Sprite;
        public TextMeshProUGUI Effect;
        private PhotonView PV;
    
        private void Awake()
        {
            PV = GetComponent<PhotonView>();
        }
    
        [PunRPC]
        public void InitializeData(object x)
        {
            Effect.text = x as string;
        }
    
    }
    

    And this is the code from the player instance in the room:
    using Photon.Pun;
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class TestController : MonoBehaviour
    {
        object[] cardData = new object[] { "Hello World!" };
        private PhotonView PV;
    
        private void Awake()
        {
            PV = GetComponent<PhotonView>();
        }
    
        private void Update()
        {
            if (PV.IsMine)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    GameObject NewCard = PhotonNetwork.Instantiate("CardFab",
                    new Vector3(0, 0, 0), Quaternion.identity, 0, cardData);
                    PhotonView PV = CardFab.GetPhotonView();
                    PV.RPC("InitializeData", RpcTarget.AllViaServer, cardData[0]);
                }
            }
            
        }
    
    }
    

    This is working 4 me! Can be closed I guess.
This discussion has been closed.