> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/scriptable-architecture/scriptables/bool-var.md).

# Bool Var

## Overview

Bool variables are Scriptable Assets that contain a bool value. They can be referenced in any script and be shared around in a project.

## How to use it

To declare a Bool Var use this code. Make sure to have the namespace:

*`using MalbersAnimations.Scriptables;`*

```csharp
using MalbersAnimations.Scriptables;

public class Example : Monobehaviour
{    
    public BoolVar myVar
}
```

This is how it looks in the Inspector:

<figure><img src="/files/1Cuuak7rATzJGrBMbFaJ" alt=""><figcaption></figcaption></figure>

## Variable Reference

There is a better way to use the scriptable variables. Instead of using **`BoolVar`** class, use **`BoolReference`** instead:

```csharp
using MalbersAnimations.Scriptables;
using UnityEngine;

public class Example : MonoBehaviour
{
    public BoolReference myVar = new BoolReference();
}

```

This is how it looks in the Inspector:

<figure><img src="/files/iowDX70tUC3mJf9IHe5s" alt=""><figcaption></figcaption></figure>

That way you have the option to use a local value or a Scriptable (global) value.

Sharing scriptable variables is an extremely useful tool to have shared values between scripts.

## Parameters

<figure><img src="/files/n6IKoEvAOeJWukEuVEb0" alt=""><figcaption></figcaption></figure>

### Value

The actual value of the scriptable variable.

### Debug \[🪲]

When enabled, the console will print a log every time the scriptable variable changes its value

### Description

Developer description to give a better explanation of what the variable does.

## Internal Events

Scriptable Variables can be listened to using the OnValue changed action.

This is the way of using it via script:

```csharp
using MalbersAnimations.Scriptables;
using UnityEngine;

public class Example : MonoBehaviour
{
    public BoolReference myVar = new BoolReference();


    private void OnEnable()
    {
        myVar.Variable.OnValueChanged += OnValueChanged;
    }

    private void OnDisable()
    {
        myVar.Variable.OnValueChanged += OnValueChanged;
    }

    private void OnValueChanged(bool value)
    {
        //listen to value changes here
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://malbersanimations.gitbook.io/animal-controller/scriptable-architecture/scriptables/bool-var.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
