Chat client value is null when button click event is fired

Hello,
My ChatClient connects, subscribes to channels successfully and none OnDisconnect event is fired on IChatClientListener.
Although there's a problem:
after hitting Refresh button I get null reference error.
That's because I've implemented refresh event listener which use ChatClient to disconnect from chat which is null.

So why my ChatClient suddenly becomes null?

Best Answer

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Hi @Luksys5,

    Thank you for choosing Photon!

    What SDK and what version are you using?
    Is this Unity? What platform?

    So you have two issues:
    - OnDisconnect callback is not triggered although you are explicitly disconnecting chat client?
    - ChatClient becomes null sometimes unexpectedly.

    Can you explain the reproduction steps with more details? I didn't really get the Refresh button scenario.
    Do you have any useful logs?

    As a workaround to avoid exceptions: you can wrap the ChatClient backing field in the property's getter in a way to always re-create the client if it's null and log an error.

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Answer ✓
    Hi @Luksys5,

    Thank you for choosing Photon!

    What SDK and what version are you using?
    Is this Unity? What platform?

    So you have two issues:
    - OnDisconnect callback is not triggered although you are explicitly disconnecting chat client?
    - ChatClient becomes null sometimes unexpectedly.

    Can you explain the reproduction steps with more details? I didn't really get the Refresh button scenario.
    Do you have any useful logs?

    As a workaround to avoid exceptions: you can wrap the ChatClient backing field in the property's getter in a way to always re-create the client if it's null and log an error.
  • I'm using Unity beta 2018.2. And I've found a problem which isn't related to photon engine.
    The problem is that on button click method target was an old prefab with same script which of course had null referenced properties. So this is mainly my fault.

    As workaround to avoid exceptions: I want my chat to be connected later, so wrapping up getter won't do any good.

    Thanks for all your answers and efforts :)