Random null reference error on " PhotonTransformViewClassic" when second player joins

Options

Hello all,

I've encountered a tricky game breaking error that I can't seem to find or understand the cause of, mainly as it also seems to happen randomly and is impossible to directly reproduce.

For the most part everything works fine however sometimes when a second player joins the game a null reference error pointing to "PhotonTransformViewClassic.cs:128" is thrown straight away and the player won't appear to the other player at all.

The strange thing is this is random and not constant at all, sometimes when a new player joins everything works fine as expected, but sometimes this happens and breaks the game as the second player never shows up. This makes it impossible to reproduce.

I had a look around the forums for issues like this occurring when another player joins and found a few threads but no working solutions. So unfortunately I have to post here to see if anyone has any ideas as to why line 128 of "PhotonTransformViewClassic" script is throwing null errors? The exact line of code is: " this.m_PositionControl.OnPhotonSerializeView(transform.localPosition, stream, info);"

I appreciate all who took the time to read this and any help/suggestions that may be provided!

Also: I am using the newest version of PUN

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    Options

    Please figure out which value is null. Is it the m_PositionControl or the transform??

    This might be due to execution order or some update is arriving before Awake ran? No idea how that should happen, so it's good to know what is null.

    Try adding a check if this.m_PhotonView is null. If so, skip the execution of OnPhotonSerializeView.

    The callstack for the exception is also of interest.

Answers

  • Tobias
    Tobias admin
    Answer ✓
    Options

    Please figure out which value is null. Is it the m_PositionControl or the transform??

    This might be due to execution order or some update is arriving before Awake ran? No idea how that should happen, so it's good to know what is null.

    Try adding a check if this.m_PhotonView is null. If so, skip the execution of OnPhotonSerializeView.

    The callstack for the exception is also of interest.

  • AnthonyM86
    Options

    Hello,


    Thanks for the reply! I managed to fix it now with this advice by adding debug.logs to list the game objects name which was throwing the null reference so I could check it out.

    It turns out I had not put PhotonView components on child objects that had their own PhotonTransformView components, hence the error. A silly mistake on my part. I'm glad I managed to fix it and I appreciate your help!

    P.S - photon PUN is very cool and I'm really enjoying experimenting with it! Keep up the great work!