photonView is null?
I'm trying to call RPC from the script, but it throws a null reference exception.
Tried refreshing the RPC list in resources doesn't change anything. Using Unity 2019.1.0f2 and PUN 2.33 Lib 4.1.6.3.
using UnityEngine; using UnityEngine.UI; using Photon.Pun; public class HitVFX : MonoBehaviourPun { [SerializeField] private Slider m_HPSlider = null; private Health m_Health = null; public Health Health { get { if (m_Health == null) { m_Health = GetComponent<Health>(); } return m_Health; } } void Start() { m_Health = GetComponent<Health>(); Initialize(); } public void Initialize() { if (m_HPSlider) { SetHPSliderMinMaxValues(); UpdateHPSlider(Health.Value); } } public void SetHPSliderMinMaxValues() { if (m_HPSlider == null) { return; } float maxHealth = Health.MaxValue; SetHPSliderMinMaxValuesInternal(maxHealth); print(photonView); // NULL HERE photonView.RPC("SetHPSliderMinMaxValuesInternal", RpcTarget.Others, maxHealth); // THROWING NULL REFERENCE EXCEPTION } [PunRPC] void SetHPSliderMinMaxValuesInternal(float maxValue) { m_HPSlider.minValue = 0; m_HPSlider.maxValue = maxValue; } }
Tried refreshing the RPC list in resources doesn't change anything. Using Unity 2019.1.0f2 and PUN 2.33 Lib 4.1.6.3.
0
Best Answer
-
Nevermind, caused by different gameobject using the same component.1
Answers
-
Note that the object that has this component is instantiated by PhotonNetwork.Instantiate.0
-
Nevermind, caused by different gameobject using the same component.1
-
Thanks for updating this and providing an answer!0