Null reference when second player joins

Hello!

I am currently using PUN2 and after creating a lobby, when the second player joins both players get a null reference exception:

NullReferenceException: Object reference not set to an instance of an object
Photon.Pun.PhotonView.SerializeComponent (UnityEngine.Component component, Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:366)
Photon.Pun.PhotonView.SerializeView (Photon.Pun.PhotonStream stream, PhotonMessageInfo info) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonView.cs:328)
Photon.Pun.PhotonNetwork.OnSerializeWrite (Photon.Pun.PhotonView view) (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1685)
Photon.Pun.PhotonNetwork.RunViewUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonNetworkPart.cs:1618)
Photon.Pun.PhotonHandler.LateUpdate () (at

if I double click the error it goes to this line: Debug.LogError("Observed scripts have to implement IPunObservable. "+ component + " does not. It is Type: " + component.GetType(), component.gameObject);

I currently don't have any scripts being observed, so why would this error even be relevant? I did a search for all PhotonViews in the scene during this error and none have an observed component.

For what its worth I successfully had two clients connect, made some changes then got this error thrown so I reverted back to the version where it was working using collab, and now this error still gets thrown.

Any ideas?

Thanks!

Comments

  • Which version of PUN are you using exactly? Please provide the PhotonNetwork.PunVersion.

    It looks like the component is null and in that case, component.GetType will fail. However, that should not be possible. If you can identify the object which is causing this, I would check the PhotonView in the "debug" mode of the inspector, to have a look at the list of components.

    SerializeComponent is only called when this.ObservedComponents != null && this.ObservedComponents.Count > 0, so somehow, there has to be some null component in the views.