Page 1 of 1
Go Back to previous focus after dialog
Posted: Wed Aug 18, 2021 4:04 pm
by Dralks
I'm sure that this has been answered before, but after reading the documentation and searched the forum I still couldn't find it, apologies.
I have a dialog opening in the menu and the continue button receives the focus (which is correct) but I want to go back to what the user had selected when the dialog closes, is there any easy option or do I need to write my own?
Re: Go Back to previous focus after dialog
Posted: Wed Aug 18, 2021 4:20 pm
by Tony Li
Hi,
You'll want to write your own. Record the current selected object before starting the conversation. Select that object when the conversation ends. Example:
Code: Select all
GameObject previousSelection = EventSystem.current.currentSelectedGameObject;
DialogueManager.instance.conversationEnded += OnConversationEnded;
void OnConversationEnded(Transform actor)
{
DialogueManager.instance.conversationEnded -= OnConversationEnded;
EventSystem.current.SetSelectedGameObject(previousSelection);
}
If you're using a Dialogue System Trigger, make a subclass that overrides DoConversationAction:
Code: Select all
public class MyDialogueSystemTrigger : DialogueSystemTrigger
{
private GameObject previousSelection;
protected override void DoConversationAction(Transform actor)
{
GameObject previousSelection = EventSystem.current.currentSelectedGameObject;
DialogueManager.instance.conversationEnded += OnConversationEnded; //(same method as above)
base.DoConversationAction(actor);
}
}
Re: Go Back to previous focus after dialog
Posted: Wed Aug 18, 2021 4:33 pm
by Dralks
I will do, thank you very much for the code
Re: Go Back to previous focus after dialog
Posted: Wed Aug 18, 2021 4:48 pm
by Tony Li
Happy to help!