Getting an error when trying to publish a message.

Options
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 ✭✭✭✭✭
    edited January 2021
    Options
    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 2021
    Options
    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.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    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.