# Alias

!!! note "Summary"
    An **Alias** gives a game object an ID of its own, such as `Player`, so any Event can find that object by ID. Use it when a prefab, an asset, or another scene needs to reach an object it can't hold a direct reference to.

![The Alias component](assets/alias-component.jpg)

## What Alias solves

Most Instructions reach an object through a reference you drag into a field. That works inside one scene, but a prefab or a [Function](../functions/index.md) asset can't store a reference to an object in a scene. A reference also stops working when a scene load destroys the object it points at.

You could search for the object by its name or tag instead, but the search breaks when someone renames the object or a second object gets the same tag. An Alias replaces the reference with an ID that belongs to the object, whatever it's called and wherever the Event that needs it lives.

## The core idea

Think of Alias as a phone book. Objects list themselves under an ID as they become active, and any Event can look up that ID:

| When | Visual Script |
| :--- | :--- |
| A game object with an **Alias** becomes active for the first time | Records its ID and the object. |
| A field using the **Alias** Signal is read | Returns the object holding that ID. |
| The object is destroyed | Removes the ID, so another object can take it. |
| Nothing holds the ID | Returns nothing, without an error. |

Here's how that looks when a prefab needs to know about something in the scene:

!!! example "A zombie prefab notices the player"
    1. Select the player in your scene, add an **Alias** component, set its dropdown to **ID**, and enter `Player`.
    2. Open the zombie prefab and add an **Event** with an **On Update** Trigger.
    3. Add an **If** with a **Compare Numbers** Condition, and check whether **Distance** is below `5`.
    4. Set the two objects that **Distance** measures to **Source** and the **Alias** Signal with the ID `Player`.
    5. Add the Instructions that start the chase inside the **If**.

    Every zombie you spawn finds the same player, and the prefab holds no reference to anything in the scene.

## Alias or other references

An Alias doesn't replace the other ways of reaching an object. It's the one to choose when your game knows a specific object by name:

| Way to reach an object | Reaches scene objects from prefabs and assets | Searches the scene | Stops working when |
| :--- | :--- | :--- | :--- |
| **Game Object** reference | No | No | A scene load destroys the object. |
| **Find by Name** | Yes | Yes | You rename the object. |
| **Find with Tag** | Yes | Yes | Another object with the tag is found first. |
| **Alias** | Yes | No | Nothing holds the ID. |

When the Event already knows the object, use **Source** or **Target** instead, because there's nothing to look up. The zombie that a bullet hits is **Target**, whereas the player is a good fit for an Alias.

!!! warning "One ID points at one object"
    An Alias doesn't group objects. If two objects ask for the same ID, the first keeps it and the second can't be found by that ID. To work with several objects, use a [Collection](../manual/signals/collections.md) instead.

## Try it

* Build the zombie example above, then rename the player. The prefab still finds it.
* Give an arrival point in another scene an ID, and use it in the **Relocates** list of **Load Scene**.
* Use the **Alias** Signal inside a [Function](../functions/index.md), which is an asset and can't hold a scene reference.
* Spawn two copies of a prefab with a fixed ID and read the error in the Console. Then switch the prefab to **Random ID** and run it again.
* Log an object's ID with **Debug Log Text** and the **Alias ID** Signal.

## Where to go next

<div class="grid cards" markdown>

- **[Installation](installation.md)** — add the module to your project.
- **[Using Aliases](using-aliases.md)** — give objects IDs, find them, and change IDs during the game.
- **[Game Object Signals](../manual/signals/game-objects.md)** — compare the other ways of choosing an object.

</div>
