Page 2 of 2
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 4:32 pm
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
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 5:48 pm
by Tony Li
What's the current issue then?
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 7:03 pm
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.
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 9:04 pm
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)
{
...
}
}
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 9:42 pm
by PayasoPrince
Just tried your change. Progress?
currentSelectedGameObject is now my Continue Button. It was previously the FastForward Button.
Still not quite there yet...
Re: Response Menu Panel Custom OnOpen
Posted: Sat Apr 30, 2022 10:28 pm
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:
Re: Response Menu Panel Custom OnOpen
Posted: Sun May 01, 2022 11:28 am
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:
This did it! CurrentSelected is now the highlighted response.
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!
Re: Response Menu Panel Custom OnOpen
Posted: Sun May 01, 2022 11:49 am
by Tony Li
Great! I'm glad you got it working the way you want.