Response Menu Panel Custom OnOpen

Announcements, support questions, and discussion for the Dialogue System.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Hello,

I created an OnOpen() Event + script that instantiates a gameobject to the scene when the Response Menu gets enabled:

Code: Select all

public void Enter()
    {
        choiceSelector = Instantiate(ChoiceSelector, selectorPos);
        Debug.Log("Instantiating Cursor next to button");
    }
I found out that this only happens for the Response Button Template. In other words, it does not happen for my actual response buttons. (Yes/No)
Image

How can I make it so that it is instantiated as a child of my first selected response, rather than the template?
From there, it seems easy enough to move it to the next response when OnMove() is called.

Thanks!
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

Hi,

If you want to instantiate the object on each button, put the script on the button, and use the Start() method to instantiate the object.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Good Morning Tony, :)

Alright I will do that :idea:

Is there a method I can use to see if the response button is currently the response that is hovered?

I am looking to do something like this:

Code: Select all

void Start()

    {
    	If(hovered)
        	{
        		choiceSelector = Instantiate(ChoiceSelector, selectorPos);
       		 	Debug.Log("Instantiating Cursor next to button");
    		}
    }
   
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

Hi,

Try EventSystem.current.currentSelectedGameObject. That will tell you what button is selected. If you need to know what button the mouse pointer is over without it being selected, you'll need to track that yourself.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Thanks for always finding the time to get back to me, Tony. I hope your weekend is going well dude!

Almost there! The problem is this is always evaluating to true for all of my Response Buttons.

Code: Select all

void Start()
    {
        if (EventSystem.current.currentSelectedGameObject)
        {
            choiceSelector = Instantiate(ChoiceSelector, selectorPos);
            Debug.Log("Testing the pointer enter event");
        }
    }
In game:
Image

I assume that if Response Menu Panel GameObject > Standard UI Menu Panel > First Selected is null, it will automatically select the first response, because it is behaving that way now. But it's worth mentioning I do not have a gameobject dragged into the inspector there.

How can I fix every Response Button returning true for EventSystem.current.currentSelectedGameObject? :?
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

Change:

Code: Select all

if (EventSystem.current.currentSelectedGameObject)
to:

Code: Select all

if (EventSystem.current.currentSelectedGameObject == this.gameObject)
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Ah, whoops. I thought currentSelectedGameObject was a bool for some reason :oops:.

I made the change you suggested and now it is always false.

I debugged this and found out that the reason it's false is because currentSelectedGameObject is the fastforward/continue button located on the NPCSubtitlePanel. I don't think currentSelectedGameObject will ever == Response Button. :cry:

Is there another method/variable I can use specific to the response panel?
Maybe something like - "IsFirstSelected"? :idea:
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

If the Dialogue Manager's Input Device Manager > Always Auto Focus checkbox is ticked, then the response menu should keep a response button selected, so EventSystem.current.currentSelectedGameObject should be one of the response buttons.

If Always Auto Focus is unticked, then a response button won't be selected until you click on it. If you want to know when the mouse is hovering over a button, you'll have to track that yourself using PointerEnter and PointerExit in an Event Trigger component or the equivalent IPointerEnterHandler/IPointerExitHandler interfaces on a script.
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Huh...that's weird. I already have "Always auto focus" ticked.

If it helps, here are the other settings in Input Device Manager:
Image

Edit: Oh, and mouse support is not needed.

But that does bring up a question. Before I changed "input device" from Mouse > Joystick, when I clicked a response button with a mouse the color successfully changed its pressed color to blue. Now that its "correctly" set to keyboard, the response buttons will still show green when they are highlighted, but when pressed they do not change to blue.
If it helps:
Image
^ ^ ^
I bring this up to ask if there is like a mouse mode or something that the response panel could be in :?:
Just brainstorming here because I really need to get this to work...
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

I don't understand. Is the Input Device Manager's Input Device mode set to Mouse, Joystick, or Keyboard?

Not that it matters if Always Auto Focus is ticked. The Input Device Mode lets the Dialogue System know when to auto focus, but Always Auto Focus is ticked the mode doesn't matter.

Are you saying that the button does not change to blue when you press the Submit input with a keyboard or joystick? If so, that's the way Unity UI works. It just registers the click, but it doesn't show the Pressed state.
Post Reply