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.
Visual Script logo Manual

On Application Focus#

Application / On Application Focus

Description#

Executes when application gains or loses the focus

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("On Application Focus")]
    [Image(typeof(IconApplication), ColorTheme.Type.TextLight)]
    
    [Description("Executes when application gains or loses the focus")]
    [Category("Application/On Application Focus")]
    
    [Keywords("Gain", "Focus", "Suspend", "Minimize")]

    [Serializable]
    public class TriggerCoreOnApplicationFocus : Trigger
    {
        [SerializeField]
        private TValueOrAny<GetBool> m_HasFocus = new TValueOrAny<GetBool>();

        protected override string GetTitle(GameObject source) => $"Application Focus = {this.m_HasFocus}";

        public override void OnEnable()
        {
            base.OnEnable();
            Application.focusChanged += this.OnChangeFocus;
        }

        public override void OnDisable()
        {
            base.OnDisable();
            Application.focusChanged -= this.OnChangeFocus;
        }

        private void OnChangeFocus(bool hasFocus)
        {
            using Args args = Args.Get(this.Component, this.Component);
            if (this.m_HasFocus.IsAny || this.m_HasFocus.Value.Get(args) == hasFocus) this.Run(args);
        }
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.