Documentation index for AI agents (llms.txt) A Markdown version of every page is available: request the page's source under /docs/, follow the "alternate" link in this page's head, or start from /llms.txt.
Game Creator 3 logo Dialogue

On Dialogue Finish#

Game Creator / Dialogue / On Dialogue Finish

Description#

Executes when a Dialogue component finishes playing

Code#

using System;
using UnityEngine;
using VisualScript.Icons;
using VisualScript.Runtime;

namespace GameCreator.Runtime.Dialogue
{
    [Title("On Dialogue Finish")]
    [Image(typeof(IconDialogue), ColorTheme.Type.Red)]

    [Description("Executes when a Dialogue component finishes playing")]
    [Category("Game Creator/Dialogue/On Dialogue Finish")]

    [Keywords("Dialogue", "Line", "Text", "Script", "Narration", "End", "Complete", "Exit")]

    [Serializable]
    public class TriggerDialogueDialogueFinish : Trigger
    {
        // EXPOSED MEMBERS: -----------------------------------------------------------------------

        [SerializeField] private TValueOrAny<GetGameObject> m_Dialogue =
            new TValueOrAny<GetGameObject>(
                ValueOrAny.Any,
                new GetGameObject(new TypeGameObjectDialogue())
            );

        // MEMBERS: -------------------------------------------------------------------------------

        [NonSerialized] private Guid m_SubscriptionDialogue;
        [NonSerialized] private Dialogue m_CurrentDialogue;

        // PROPERTIES: ----------------------------------------------------------------------------

        protected override string GetTitle(GameObject source) =>
            this.m_Dialogue.IsSpecific
                ? $"On Finish {this.m_Dialogue}"
                : "On Finish any Dialogue";

        // INITIALIZERS: --------------------------------------------------------------------------

        public override void OnEnable()
        {
            base.OnEnable();

            using Args args = Args.Get(this.Component, this.Component);

            if (this.m_Dialogue.IsAny)
            {
                Dialogue.EventFinish += OnFinishAny;
            }
            else
            {
                this.m_SubscriptionDialogue = this.m_Dialogue.Value.Subscribe(this.OnChangeDialogue, args);
                this.OnChangeDialogue(args);
            }
        }

        public override void OnDisable()
        {
            base.OnDisable();

            if (this.m_CurrentDialogue != null)
            {
                this.m_CurrentDialogue.EventDialogueFinish -= this.OnFinishDialogue;
            }

            Dialogue.EventFinish -= OnFinishAny;
            this.m_Dialogue.Value.Unsubscribe(this.m_SubscriptionDialogue);
        }

        // CALLBACK METHODS: ----------------------------------------------------------------------

        private void OnFinishAny(Dialogue dialogue)
        {
            using Args args = Args.Get(this.Component.gameObject, dialogue);
            this.Run(args);
        }

        private void OnChangeDialogue(Args args)
        {
            if (this.m_CurrentDialogue != null)
            {
                this.m_CurrentDialogue.EventDialogueFinish -= this.OnFinishDialogue;
            }

            this.m_CurrentDialogue = this.m_Dialogue.Value.Get<Dialogue>(args);

            if (this.m_CurrentDialogue != null)
            {
                this.m_CurrentDialogue.EventDialogueFinish += this.OnFinishDialogue;
            }
        }

        private void OnFinishDialogue(Dialogue dialogue)
        {
            using Args args = Args.Get(this.Component.gameObject, dialogue);
            this.Run(args);
        }
    }
}
Game Creator 3 logoGame Creator 3 © Catsoft Works 2026. All rights reserved.