How do I quit the game via dialogue?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Eldritch_Horror
Posts: 28
Joined: Sun May 28, 2023 8:30 pm

How do I quit the game via dialogue?

Post by Eldritch_Horror »

How do I have a dialogue option quit the game?
lgarczyn
Posts: 30
Joined: Fri May 05, 2023 5:28 am

Re: How do I quit the game via dialogue?

Post by lgarczyn »

Create a scriptableobject like so, it should be in a file called ApplicationBridge.cs

Code: Select all

  [CreateAssetMenu(menuName = "Game/ApplicationBridge", fileName = "Application Bridge")]
  public class ApplicationBridge: ScriptableObject
  {
    public void Quit()
    {
      Application.Quit();
    }
  }
Then, in an asset folder, right-click => create => Game => Application Bridge

In your dialogue, select the user response that should quit the game, add an event

Image

Press "plus", select your Application Bridge asset, then select "Quit" on it.

You can use this to call any function on any scriptable object from a dialogue entry.

You can of course name it however you want, like "QuitGame" or "GameExitBridge"
User avatar
Tony Li
Posts: 21681
Joined: Thu Jul 18, 2013 1:27 pm

Re: How do I quit the game via dialogue?

Post by Tony Li »

^ That's a good suggestion.

Alternatively, you can write a sequencer command:

SequencerCommandQuitGame.cs

Code: Select all

using UnityEngine;
namespace PixelCrushers.DialogueSystem.SequencerCommands
{
    public class SequencerCommandQuitGame : SequencerCommand
    {
        private void Awake()
        {
#if UNITY_EDITOR
            UnityEditor.EditorApplication.isPlaying = false;
#endif
            Application.Quit();
            Stop();
        }
    }
}
Then set the dialogue entry node's Sequence field to: QuitGame()
Eldritch_Horror
Posts: 28
Joined: Sun May 28, 2023 8:30 pm

Re: How do I quit the game via dialogue?

Post by Eldritch_Horror »

Thank you both! Works a treat. I really appreciate the support. :)
Post Reply