Custom Instantiation Data
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Custom Instantiation Data : Send GameObject or Components ?
Jimanji
2020-03-28 20:13:36
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
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.
Ok thank you, that help me.
@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.
@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];
}
}
Back to top