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

Set Cursor Lock State#

Input / Cursor / Set Cursor Lock State

Description#

Changes whether the mouse cursor is locked to the center of the view, confined to the window or free

Parameters#

Name Description
Lock State Locked keeps the cursor at the center of the view, Confined keeps it inside the window and None frees it

Code#

using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Title("Set Cursor Lock State")]
    [Category("Input/Cursor/Lock State")]
    [Description("Changes whether the mouse cursor is locked to the center of the view, confined to the window or free")]

    [Image(typeof(IconCursor), ColorTheme.Type.Blue)]
    [Keywords("Mouse", "Pointer", "Lock", "Unlock", "Confine", "Free", "Capture")]

    [Parameter("Lock State", "Locked keeps the cursor at the center of the view, Confined keeps it inside the window and None frees it")]

    [Serializable]
    public class InstructionCursorSetLockState : Instruction
    {
        [SerializeField] private CursorLockMode m_LockState = CursorLockMode.Locked;

        protected override string GetTitle(GameObject source)
        {
            string className = TextUtils.ThemeAsKeyword("Cursor");
            string member = TextUtils.ThemeAsKeyword("Lock State");
            return $"{className} {member} = {this.m_LockState}";
        }

        protected override Awaitable Run(Args args)
        {
            Cursor.lockState = this.m_LockState;
            return Done;
        }
    }
}
Visual Script logoVisual Script © Catsoft Works 2026. All rights reserved.