---
tags:
    - "If"
    - "Condition"
    - "Switch"
---

# If

[Control](index.md) / **If**

## Description

Checks a condition and executes the Instructions if it's true

## Parameters

| Name | Description |
| :--- | :---------- |
| Conditions | The conditions to check |
| Instructions | The instructions to run |

## Code

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

namespace VisualScript.Runtime
{
    [Title("If")]
    [Image(typeof(IconIf), ColorTheme.Type.Blue)]
    
    [Description("Checks a condition and executes the Instructions if it's true")]
    [Category("Control/If")]
    
    [Parameter("Conditions", "The conditions to check")]
    [Parameter("Instructions", "The instructions to run")]
    
    [Keywords("If", "Condition", "Switch")]
    
    [NestInnerList(nameof(m_Conditions))]
    [NestOuterList(nameof(m_Instructions))]
    
    [Serializable]
    public class InstructionCoreConditionIf : Instruction
    {
        [SerializeField] private Conditions m_Conditions = new Conditions();
        [SerializeField] private Instructions m_Instructions = new Instructions();

        protected override string GetTitle(GameObject source) => $"If {this.m_Conditions}";

        protected override async Awaitable Run(Args args)
        {
            if (this.m_Conditions.Check(args, Conditions.DEFAULT_OPERATION))
            {
                await this.m_Instructions.Run(args, this.ParentCancelToken);
                this.CurrentResult = InstructionResult.Success;
            }
            else
            {
                this.CurrentResult = InstructionResult.Failure;
            }
        }
        
        public override void OnCancel()
        {
            base.OnCancel();
            this.m_Instructions.Cancel();
        }
    }
}
```

