Response event is null?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
DaynerKurdi
Posts: 2
Joined: Mon May 26, 2025 7:26 am

Response event is null?

Post by DaynerKurdi »

I have a problem processing my responses from the dialogue system,

The event EventHandler<SelectedResponseEventArgs> SelectedResponseHandler; is throwing null, and I'm not sure where the problem is.

My dialogue class is a subclass of the StandardDialogueUI.

I override the ShowResponses, perform my responses logic, and then pass it to the base.

Everything is working till I send a selected response via the code "gamepad" press, keep getting null on the event,
I double-checked if it was the response, but I do see my response showing up with dialogue system info as selection or with the breakpoint.

It does seem that my implementation of SelectedResponseHandler is off.

It does work if I select my response with a mouse click; it does show up my response, once in the dialogue info, so I'm not sure where the problem is.

Here is my code.

Code: Select all

public override void ShowResponses(Subtitle subtitle, Response[] responses, float timeout)
        {
            // Add your code here to show the player response menu. Populate the menu with the contents
            // of the responses array. When the player selects a response, call:
            //    SelectedResponseHandler(this, new SelectedResponseEventArgs(response));
            // where the argument "response" is the response that the player selected.
            // If (timeout > 0), auto-select a response when timeout seconds have passed.


            responseContextsArray = new ResponseContext[responses.Length];

            for (int i = 0; i < responseContextsArray.Length; i++)
            {
                responseContextsArray[i] = new ResponseContext(
                    responses[i],
                    conversationUIElements.menuPanels[0].buttons[i],
                    selectedResponseScaler,
                    responseScalerMaxLerpTime
                );
            }

            enableResponseInputFlag = true;
            skip = true;
            
            base.ShowResponses(subtitle, responses, timeout);
        }
Here is how I process my responses

Code: Select all

 private void CommitResponseForwardEventObserver()
        {
            if (enableResponseInputFlag && skip == false)
            {
                Response temp = responseContextsArray[currentResponseIndex].GetResponse();
                
                SelectedResponseHandler(this, new SelectedResponseEventArgs(temp));
            }

            skip = false;
        }
User avatar
Tony Li
Posts: 23278
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response event is null?

Post by Tony Li »

Hi,

When the Dialogue System starts a conversation, it creates a ConversationModel (handles conversation logic), ConversationView (handles UIs), and ConversationController (coordinates between Model & View).

If you're using StandardUIResponseButton components on your response buttons, just call the button's StandardUIResponseButton.OnClick() method. You don't need to touch SelectedResponseHandler.

Otherwise, if you just want to send a response directly to the dialogue UI, call the dialogue UI's OnClick(Response) method. This will send the response from the dialogue UI to the conversation's ConversationView. The ConversationView will send the response to the ConversationController, which will then get the next state from the ConversationModel.
DaynerKurdi
Posts: 2
Joined: Mon May 26, 2025 7:26 am

Re: Response event is null?

Post by DaynerKurdi »

Oh, you could do that, never thought about it XD

I tested it and, like you said, it did work. Many thanks.

But could you tell the proper way to use EventHandler<SelectedResponseEventArgs> SelectedResponseHandler? been looking awaond through out the code and kind bug me
User avatar
Tony Li
Posts: 23278
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response event is null?

Post by Tony Li »

You shouldn't touch it. It's for use by ConversationController and ConversationView, not for direct use by dialogue UIs.
Post Reply