NullReferenceException with Photon RPC, please help

Hello everyone. I am very new in Photon Network and recently I was using RPC to send message to all players in the room:

But on the stroke "pv.RPC("SendData", RpcTarget.AllBuffered, newMessage);" unity gives me log error:

NullReferenceException: Object reference not set to an instance of an object
ChatScript.SendMessage () (at Assets/Scripts/ChatScript.cs:29)
UnityEngine.Events.InvokableCall.Invoke () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
UnityEngine.Events.UnityEvent.Invoke () (at <f1212ad1dec44ce7b7147976b91869c3>:0)
UnityEngine.UI.Button.Press () (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:70)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/UI/Core/Button.cs:114)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:57)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/ExecuteEvents.cs:272)
UnityEngine.EventSystems.EventSystem:Update() (at Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:501)

I checked all my variables through printing them and they're fine. "pv" - PhotonView is also fine, I get in the Start method (previously set it like a variable):

Also here's my server settings:


Thanks in advance!

Comments

  • I can't see why pv.RPC("SendData", RpcTarget.AllBuffered, newMessage); should be null if the GameObject has a PhotonView component. Maybe your UI references another instance and that doesn't have a PhotonView component?

    Sorry, this is something you have to debug, as we can't check the project.