Go Back to previous focus after dialog

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Dralks
Posts: 44
Joined: Mon May 24, 2021 6:19 pm

Go Back to previous focus after dialog

Post 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?
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Go Back to previous focus after dialog

Post 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);
    }
}
Dralks
Posts: 44
Joined: Mon May 24, 2021 6:19 pm

Re: Go Back to previous focus after dialog

Post by Dralks »

I will do, thank you very much for the code
User avatar
Tony Li
Posts: 22159
Joined: Thu Jul 18, 2013 1:27 pm

Re: Go Back to previous focus after dialog

Post by Tony Li »

Happy to help!
Post Reply