# Projectile

A **Projectile** is the `GameObject` that gets spawned and (probably) moves around the world looking for a target to smash into.

The Projectile component has a number of `Scriptable Objects` which determine how the projectile behaves in the world, from spawning, to motion, destruction, speed, and more.

<figure><img src="/files/Resk5OA7rAfnW9Djj0aE" alt=""><figcaption><p>The "Bullet Blue" projectile from the Sci-Fi Arsenal integration.</p></figcaption></figure>

The custom Inspector is where you add all the details required to make an awesome projectile! The overviews below will introduce you to each section. Check the detailed pages for complete information.

{% hint style="success" %}
The `Scriptable Objects` referenced in the Projectile Inspector can be edited directly in this view. However, the data still lives on those objects, so any changes to the `Scriptable Object` data here will affect all other Projectiles which use the same data or behaviors.

You can click the "*Replace w/ Copy*" button to create a copy of any behavior, to customize it without affecting other projectiles.
{% endhint %}

## **Projectile Data**

Each **Projectile** needs a [**Projectile Data**](/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile/projectile-data.md) object attached to it. This will hold specific data like speed or other things, which the [**Behaviors**](/magic-pig-games/projectile-factory/projectile-factory-documentation/behaviors.md) will make use of.

You may want to create a class which inherits from `ProjectileData`, to include custom information and logic for your project.

{% content-ref url="/spaces/-MY3N\_li2jPq7az6mYfq/pages/mavFg4pPGfTEMn6BWNSB" %}
[Projectile Data](/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile/projectile-data.md)
{% endcontent-ref %}

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

## Spawn Behavior & Spawn Behavior Modification

The [**Spawn Behavior** ](broken://pages/yyEuyK09NuApk8jSEbXs)for the **Projectile**, along with any [**Spawn Behavior Modifications**](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior.md) determine how the projectiles are spawned. This includes the speed at which they are spawned, and even how many -- from a single projectile to a machine gun, and more.

The Spawn Behavior Modifications are optional behavior scripts that fire once, right after the Projectile is spawned, and before any Behaviors activate.  You can have as many **Spawn Behavior Modifications** as you'd like.

{% hint style="info" %}
In the demo scenes, any "Laser" Projectile will have a "Parent to Spawn Point" modification, which ensures the Projectile is parented properly to the spawn point, so it can rotate as expected.

Many Projectiles also use a **Spawn Behavior Modification** to create a "Muzzle" particle, as shown above.
{% endhint %}

{% content-ref url="/pages/ocEGiLwxW64pwN2u4WNN" %}
[Spawn Behavior](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior.md)
{% endcontent-ref %}

{% content-ref url="/pages/cZwiQ2qpHhJTmmrYW876" %}
[Spawn Behavior Modification](/magic-pig-games/projectile-factory/projectile-factory-documentation/spawn-behavior/spawn-behavior-modification.md)
{% endcontent-ref %}

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

## Behaviors

[**Behaviors**](/magic-pig-games/projectile-factory/projectile-factory-documentation/behaviors.md) determine how the Projectile behaves (get it?). From movement through collision and destructions, each Behavior will typically do a single thing. This allows you to quickly build up the behavior of any particular Projectile, and easily modify behaviors to create the perfect Projectile for your project.

You can also create your own Behaviors! If you want something that doesn't exist already, it's easy to create a new behavior, or override an existing one to customize things exactly as you'd like for your project.

{% content-ref url="/spaces/-MY3N\_li2jPq7az6mYfq/pages/hkd03zUfDZIszcRt5eYe" %}
[Behaviors](/magic-pig-games/projectile-factory/projectile-factory-documentation/behaviors.md)
{% endcontent-ref %}

{% content-ref url="/pages/cOvcpSLFrO7o9Ft0Kzdl" %}
[Create Custom Behaviors](/magic-pig-games/projectile-factory/projectile-factory-documentation/create-custom-behaviors.md)
{% endcontent-ref %}

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

## Events

Each **Projectile** has `UnityEvents` exposed, allowing you to hook into the Projectile lifecycle.

{% hint style="warning" %}
The **Projectile** itself is a `Scriptable Object`, so it can not have any scene objects added to the `UnityEvents`. To make use of these events, check the "*Projectile Events*" tab on the [**Projectile Spawner**](/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile-spawner.md).

The `UnityEvent` settings in that section will be copied to every **Projectile** the spawner creates, allowing for in-scene hooks to each **Projectile**.
{% endhint %}

## Options

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

### Register with Factory Manager

The [**Factory Manager**](/magic-pig-games/projectile-factory/projectile-factory-documentation/factory-manager.md) allows for [**Global Observers**](/magic-pig-games/projectile-factory/projectile-factory-documentation/observers-global-observers-and-observer-objects.md) to react based on all projectile lifecycle events. Toggle this off if you do not want this projectile to register itself with the Factory Manager.

### Object Pooling

Keep this toggle on to use the built in [**Object Pooling**](#object-pooling) system. When false, this projectile will instantiate and destroy during runtime.

### Trajectory

Each projectile can have an optional pre-launch [**Trajectory**](/magic-pig-games/projectile-factory/projectile-factory-documentation/trajectory.md), intended to provide some sort of indication to the player about where the projectile may go. Projectile Factory ships with a few trajectories, and you can create your own as well.


---

# Agent Instructions: 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:

```
GET https://infinitypbr.gitbook.io/magic-pig-games/projectile-factory/projectile-factory-documentation/projectile.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
