Page 1 of 2

Response Menu Panel Custom OnOpen

Posted: Fri Apr 29, 2022 9:44 pm
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!

Re: Response Menu Panel Custom OnOpen

Posted: Fri Apr 29, 2022 11:21 pm
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.

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 10:38 am
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");
    		}
    }
   

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 11:42 am
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.

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 12:24 pm
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? :?

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 2:24 pm
by Tony Li
Change:

Code: Select all

if (EventSystem.current.currentSelectedGameObject)
to:

Code: Select all

if (EventSystem.current.currentSelectedGameObject == this.gameObject)

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 3:15 pm
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:

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 3:32 pm
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.

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 4:10 pm
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...

Re: Response Menu Panel Custom OnOpen

Posted: Sat Apr 30, 2022 4:26 pm
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.