# Animal Brain

## Overview

The Animal brain component is used to give life to animals that are not controlled by player Input.

It is heavily based on the Unity Tutorial: [**Pluggable AI with Scriptable Objects**](https://youtu.be/cHUXh5biQMg)

Based on[ **AI States**](https://malbersanimations.gitbook.io/animal-controller/main-components/ai/animal-brain/ai-states) and [**Decisions** ](https://malbersanimations.gitbook.io/animal-controller/main-components/ai/animal-brain/decisions)you can give [**Tasks** ](https://malbersanimations.gitbook.io/animal-controller/main-components/ai/animal-brain/tasks)to the animal to wander, attack the player on sight , be your companion.. etc.

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FjpOU3664zqbkV67kWuBH%2Fimage.png?alt=media&#x26;token=1a4d3171-8949-4830-89cc-82003b68a67a" alt=""><figcaption></figcaption></figure>

## Parameters

### Eyes

Reference for a GameObject that it will be used on Tasks and decisions alike to cast rays  and execute logics using a reference point.

### Current AI State

Starting AI State the brain will execute

### Transition Cool Down

Time needed to make a new transition. Necessary to avoid Changing to multiple States in the same frame

### Remove AI on Death

Removes all AI Components when the Animal Dies. (Brain, AiControl, Agent).

## Events

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2Fb5jIk6dnemD0lGqddHdd%2Fimage.png?alt=media&#x26;token=9ecfe213-5775-4e3b-ace4-336d14f348db" alt=""><figcaption></figcaption></figure>

### On AI State Changed

Invoked when a new State starts. It uses the AI State ID as parameter

### On Task Started

Invoked when a new Task starts. It uses the AI State ID as parameter.

It is only Invoked if the Task ID is different of zero\[0].

### On Task Done

Invoked when a task has completed. It uses the AI State ID as parameter

### On Decision Succeeded

Invoked when a decision succeeded. It uses the AI State ID as parameter.

## Debug

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F3ZLIV2x8kg9eyX9Zxh4S%2Fimage.png?alt=media&#x26;token=7ce8f2bd-ddfd-4cde-b239-715b291332fd" alt=""><figcaption></figcaption></figure>

### Debug On Screen

Shows the debug window on the screen for the animal when playing:<br>

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FdokQZ6qOZP500BJEOV1t%2Fimage.png?alt=media&#x26;token=62056462-d811-4cf2-9616-07321436ba11" alt=""><figcaption></figcaption></figure>
