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

Play Script#

Game Creator / Dialogue / Play Script

Description#

Plays a Script without a Dialogue component

Parameters#

Name Description
Script The Script to play
Skin The Skin that displays the Script
Await Determines if the instruction waits till the Script is finished

Code#

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

namespace GameCreator.Runtime.Dialogue
{
    [Title("Play Script")]
    [Image(typeof(IconScriptScript), ColorTheme.Type.Yellow)]

    [Description("Plays a Script without a Dialogue component")]
    [Category("Game Creator/Dialogue/Play Script")]

    [Parameter("Script", "The Script to play")]
    [Parameter("Skin", "The Skin that displays the Script")]
    [Parameter("Await", "Determines if the instruction waits till the Script is finished")]

    [Keywords("Dialogue", "Script", "Play", "Start", "Begin")]

    [Serializable]
    public class InstructionDialoguePlayScript : Instruction
    {
        private const string DIALOGUE_NAME = "Runtime Dialogue";

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

        [SerializeField] private GetScriptableObject m_Script = new GetScriptableObject(
            new TypeScriptableObjectScript()
        );

        [SerializeField] private GetScriptableObject m_Skin = new GetScriptableObject(
            new TypeScriptableObjectDialogueSkin()
        );

        [SerializeField] private GetBool m_Await = new GetBool(false);

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

        [NonSerialized] private Dialogue m_Awaiting;

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

        protected override string GetTitle(GameObject source) => $"Play {this.m_Script} with {this.m_Skin}";

        // RUN METHOD: ----------------------------------------------------------------------------

        protected override async Awaitable Run(Args args)
        {
            Script script = this.m_Script.Get<Script>(args);
            if (script == null) return;

            DialogueSkin skin = this.m_Skin.Get<DialogueSkin>(args);
            bool isAwait = this.m_Await.Get(args);

            GameObject instance = new GameObject(DIALOGUE_NAME)
            {
                hideFlags = EditorUtils.AuxiliaryComponentsHideFlags
            };

            Dialogue dialogue = instance.AddComponent<Dialogue>();
            Awaitable awaitable = dialogue.Play(script, args.Target, skin);

            if (!isAwait)
            {
                awaitable.Fire(instance, DestroyInstance, instance);
                return;
            }

            this.m_Awaiting = dialogue;

            try
            {
                await awaitable;
            }
            finally
            {
                this.m_Awaiting = null;
                DestroyInstance(instance);
            }
        }

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

            if (this.m_Awaiting == null) return;
            this.m_Awaiting.Cancel();
        }

        // PRIVATE METHODS: -----------------------------------------------------------------------

        private static void DestroyInstance(GameObject instance)
        {
            if (instance == null) return;
            UnityEngine.Object.Destroy(instance);
        }
    }
}
Game Creator 3 logoGame Creator 3 © Catsoft Works 2026. All rights reserved.