On Click Event works only on Master Client. PUN 2
Hello! I am using Photon (PUN 2) recently. And I have the next question
I have a button, but when I click on it from a non-master client, nothing happens. The button works, I'm sure. Here is my code:
[SerializeField] private GameObject photonUserPrefab = default;
[SerializeField] private GameObject button = default;
[SerializeField] private GameObject cube = default;
...
private void Start()
{
if (PhotonNetwork.PrefabPool is DefaultPool pool)
{
if (photonUserPrefab != null) pool.ResourceCache.Add(photonUserPrefab.name, photonUserPrefab);
if (button != null) pool.ResourceCache.Add(button.name, button);
if (cube != null) pool.ResourceCache.Add(cube.name, cube);
}
}
...
private void CreateInteractableObjects()
{
var bb = PhotonNetwork.Instantiate(button.name, button.transform.position, button.transform.rotation);
bb.GetComponentInChildren<Interactable>().OnClick.AddListener(OnClick);
}
private void OnClick()
{
var cube_ = PhotonNetwork.Instantiate(cube.name, cube.transform.position, cube.transform.rotation);
}
Please, help me! It I really need to understand what the matter is.
без-имени.png
(30.5 kB)
Comment
Best Answer
Answer by koptehe · Nov 23, 2020 at 12:35 PM
I resolved this issue. It's all about the RPC Target. I used All instead of All Buffered. The difference is that some RPCs are only done with connected users, and some can be done with new arrivals.