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

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Input Device is set to joystick in Input Device Manager.

You can disregard the second part about the color press, just thought it might be relevant
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

What's the current issue then?
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

The current issue is even though I have "Always Auto Focus" ticked, the currentSelectedGameObject is my Fastforward/Continue button in the NPC Panel and not the response button in the first response panel. :cry:
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

I just took another look at your code excerpt. That makes sense, since Start() runs only once when the response button is first created. To prevent garbage allocations, the dialogue UI pools response buttons and re-uses them. However, you won't want to use OnEnable() directly because this will run as soon as the button is pulled out of the pool and re-enabled, but before it's selected. Instead, you'll need to wait until the end of the frame. Something like this:

Code: Select all

void OnEnable()
{
    StartCoroutine(OnEnableCoroutine());
}
IEnumerator OnEnableCoroutine()
{
    yield return new WaitForEndOfFrame();
    if (EventSystem.current.currentSelectedGameObject)
    {
        ...
    }
}
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Just tried your change. Progress? :shock:

currentSelectedGameObject is now my Continue Button. It was previously the FastForward Button.

Still not quite there yet...
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

I'm still not clear on what your intent is, but you could make it wait until the next frame by changing the yield line to:

Code: Select all

yield return null;
User avatar
PayasoPrince
Posts: 104
Joined: Thu Jan 27, 2022 6:47 pm

Re: Response Menu Panel Custom OnOpen

Post by PayasoPrince »

Tony Li wrote: Sat Apr 30, 2022 10:28 pm I'm still not clear on what your intent is
All I wanted to do was create my own cursor (like an arrow), that get's created next to the first highlighted response button.
Tony Li wrote: Sat Apr 30, 2022 10:28 pm you could make it wait until the next frame by changing the yield line to:

Code: Select all

yield return null;
This did it! CurrentSelected is now the highlighted response. :D

From there, I added:

Code: Select all

public void Update()
    {   
        if(choiceSelector != null)
        {
            choiceSelector.transform.position = new Vector3(transform.position.x, EventSystem.current.currentSelectedGameObject.transform.position.y - 30, transform.position.z);

        }
    }
It now follows the player's highlighted response button. Thanks! 8-)
User avatar
Tony Li
Posts: 21977
Joined: Thu Jul 18, 2013 1:27 pm

Re: Response Menu Panel Custom OnOpen

Post by Tony Li »

Great! I'm glad you got it working the way you want.
Post Reply