I am trying to understand the Photon Pun architecture. I cannot get the callback OnPhotonSerializeView()
in 'IPunObservable
' to be called.
What I have in my scene is
a
GameObject
calledDataHandler
at the top of the hierachyDataHandler
has aPhotonView
andPhotonTransformView
attachedDataHandler
also has a script attached calledDataHandler
The
DataHandler
script component has been dragged to the first observable in the PhotonView component (so it shows 'DataHandler (DataHandler)
' as the observed component).The DataHandler script implements
IPunObservable
, and the one method in that ispublic class DataHandler : MonoBehaviourPunCallbacks, IPunObservable { .... public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { Debug.Log("OnPhotonSerializeView(): " + (stream.IsWriting ? "writing" : "reading")); } .... }
Nothing shows up in the log when it is run.
However when built and run as a Windows EXE, connected with a room in place, it comes up with NullReferenceExceptions. The log shows:
NullReferenceException: Object reference not set to an instance of an object
at Photon.Pun.PhotonView.SerializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) [0x0001e] in C:\Users\nick\Documents\Unity3D\PhotonPunTest\Assets\Photon\PhotonUnityNetworking\Code\PhotonView.cs:368
at Photon.Pun.PhotonView.SerializeView (Photon.Pun.PhotonStream stream, Photon.Pun.PhotonMessageInfo info) [0x00024] in C:\Users\nick\Documents\Unity3D\PhotonPunTest\Assets\Photon\PhotonUnityNetworking\Code\PhotonView.cs:330
at Photon.Pun.PhotonNetwork.OnSerializeWrite (Photon.Pun.PhotonView view) [0x00089] in C:\Users\nick\Documents\Unity3D\PhotonPunTest\Assets\Photon\PhotonUnityNetworking\Code\PhotonNetworkPart.cs:1593
at Photon.Pun.PhotonNetwork.RunViewUpdate () [0x000b3] in C:\Users\nick\Documents\Unity3D\PhotonPunTest\Assets\Photon\PhotonUnityNetworking\Code\PhotonNetworkPart.cs:1522
at Photon.Pun.PhotonHandler.LateUpdate () [0x00042] in C:\Users\nick\Documents\Unity3D\PhotonPunTest\Assets\Photon\PhotonUnityNetworking\Code\PhotonHandler.cs:155
(Filename: C:/Users/nick/Documents/Unity3D/PhotonPunTest/Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs Line: 368)
and the code around line 368 in PhotonView.cs
is
protected internal void SerializeComponent(Component component, PhotonStream stream, PhotonMessageInfo info)
{
IPunObservable observable = component as IPunObservable;
if (observable != null)
{
observable.OnPhotonSerializeView(stream, info);
}
else
{
Debug.LogError("Observed scripts have to implement IPunObservable. "+ component + " does not. It is Type: " + component.GetType(), component.gameObject);
}
}
(The Debug.LogError
line is 368).
Don't see what is wrong, though I assume component
is probably null
. The script is implementing IPunObservable
. Can anyone help?