Getting an error when trying to publish a message.

Heres the error I'm getting:
NullReferenceException: Object reference not set to an instance of an object
PhotonChatManager.SubmitPublicChatOnClick () (at Assets/Scripts/PhotonChatManager.cs:88)

This is my code at line 88:
public void SubmitPublicChatOnClick()
{
if (privateReceiver == "")
{
Debug.Log(currentChat);
line88--> chatClient.PublishMessage("RegionChannel", currentChat);
chatField.text = "";
currentChat = "";
}
}

Comments

  • JohnTube
    JohnTube mod
    edited January 20
    Hi @Chum,

    Thank you for choosing Photon!

    The exception is in your custom code (PhotonChatManager is your own custom class).
    So I'm guessing chatClient is null at that point and needs to be initialized (chatClient = new ChatClient...)
  • Chum
    Chum
    edited January 21
    JohnTube wrote: »
    Hi @Chum,

    Thank you for choosing Photon!

    The exception is in your custom code (PhotonChatManager is your own custom class).
    So I'm guessing chatClient is null at that point and needs to be initialized (chatClient = new ChatClient...)

    Hi, where should I put this? I already have a:
    ChatClient chatClient;

    chatClient = new ChatClient gives me a error.
  • Hi @Chum,

    Could you copy/paste the error here?
    You need to initialize the ChatClient properly using its constructor.
    The PUN package contains Chat Demo, I invite you to take a look at it and see how the chatClient is initialized there.