title: Unity Photon PUN - unable to get IPunObservable call back to operate
body: <p>I am trying to understand the Photon Pun architecture. I cannot get the callback <code>OnPhotonSerializeView()</code> in '<code>IPunObservable</code>' to be called.</p>
  <p>What I have in my scene is</p>
  <ul>
  <li><p>a <code>GameObject</code> called <code>DataHandler</code> at the top of the hierachy</p>
  </li>
  <li><p><code>DataHandler</code> has a <code>PhotonView</code> and <code>PhotonTransformView</code> attached</p>
  </li>
  <li><p><code>DataHandler</code> also has a script attached called <code>DataHandler</code></p>
  </li>
  <li><p>The <code>DataHandler</code> script component has been dragged to the first observable in the PhotonView component (so it shows '<code>DataHandler (DataHandler)</code>' as the observed component).</p>
  </li>
  <li><p>The DataHandler script implements <code>IPunObservable</code>, and the one method in that is</p>
  <pre><code> public class DataHandler : MonoBehaviourPunCallbacks, IPunObservable
   {
   ....
  
       public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
       {
           Debug.Log(&quot;OnPhotonSerializeView(): &quot; + (stream.IsWriting ? &quot;writing&quot; : &quot;reading&quot;));
       }
   ....
   }
  </code></pre>
  </li>
  </ul>
  <p>Nothing shows up in the log when it is run.</p>
  <p>However when built and run as a Windows EXE, connected with a room in place, it comes up with NullReferenceExceptions. The log shows:</p>
  <pre><code>    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)
  </code></pre>
  <p>and the code around line 368 in <code>PhotonView.cs</code> is</p>
  <pre><code>    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(&quot;Observed scripts have to implement IPunObservable. &quot;+ component + &quot; does not. It is Type: &quot; + component.GetType(), component.gameObject);
          }
      }
  </code></pre>
  <p>(The <code>Debug.LogError</code> line is 368).</p>
  <p>Don't see what is wrong, though I assume <code>component</code> is probably <code>null</code>. The script is implementing <code>IPunObservable</code>. Can anyone help?</p>