---
tags:
    - "Variable"
---

# Local Variable

[Components](../index.md) / [Variables](index.md) / **Local Variable**

<div class="grid cards" markdown>

* :green_circle: Can Read

* :red_circle: Cannot Write

</div>

## Description

The Local Variable component attached to a Game Object

## Code

```cs
using System;
using UnityEngine;
using VisualScript.Icons;

namespace VisualScript.Runtime
{
    [Get]
    
    [Inline(nameof(m_Value), typeof(LocalVariable), true)]
    
    [Title("Local Variable")]
    [Category("Components/Variables/Local Variable")]
    [Description("The Local Variable component attached to a Game Object")]
    
    [Image(typeof(IconVariable), ColorTheme.Type.TextLight, typeof(BadgeVariable))]
    [Keywords("Variable")]
    
    [Serializable]
    public class TypeGameObjectComponentLocalVariable : TypeGameObject
    {
        [SerializeField] private LocalVariable m_Value;
        
        public TypeGameObjectComponentLocalVariable()
        {
            this.m_Value = null;
        }
        
        public TypeGameObjectComponentLocalVariable(LocalVariable component)
        {
            this.m_Value = component;
        }

        public override GameObject GetPreview(GameObject source) =>
            this.m_Value != null
                ? this.m_Value.gameObject
                : null;

        public override GameObject Get(Args args)
        {
            return this.m_Value != null
                ? this.m_Value.gameObject
                : null;
        }
        
        public override U Get<U>(Args args)
        {
            if (typeof(U) == typeof(LocalVariable))
            {
                return this.m_Value != null
                    ? this.m_Value as U
                    : null;
            }
            
            return base.Get<U>(args);
        }
        
        public override string ToString()
        {
            return TextUtils.Name(this.m_Value);
        }
        
        protected override SubscriptionMode Subscription => SubscriptionMode.OnEditorChange;
    }
}
```

