# IProjectileFactoryCollisionReceiver

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FtODOCPNWdXgLABYjbe8c%2FJuicyProjectiles.gif?alt=media&#x26;token=4ee110e7-de6d-467d-811a-2f796ac53165" alt=""><figcaption></figcaption></figure>

The `IProjectileFactoryCollisionReceiver` interface can be used to ensure that collisions executed by non-physics based methods such as `ProjectileRaycastHitDetector` or `InstantHitForward` properly know they've been hit.

{% hint style="info" %}
Each of the main demo projectiles has various ways of colliding, to demonstrate the various behaviors that can be used. For objects such as the cubes and spheres in the [**Juicy Actions Integration**](https://infinitypbr.gitbook.io/magic-pig-games/juicy-actions/integrations/projectile-factory), these are "simple" objects — they don't have an `Actor` component on them or anything like the enemy characters do.

They utilize the `ActionOnPhysicsEvent` component, which handles both `Trigger` and `Collider`, but those won't fire when the collision from the projectile doesn't use triggers or colliders via physics. We can use this interface to pass information along, and handle it accordingly, i.e. calling the proper `ActionExecutor`.
{% endhint %}

This interface has one method:&#x20;

```csharp
OnProjectileFactoryCollisionEnter(in ProjectileCollisionMessage message)
```

When `ProjectileRaycastHitDetector` or `InstantHitForward` have the optional `sendCollisionEnterToCollider`, then any object that was detected will have this method called if the interface is present.

## Projectile Collision Message

The struct ProjectileCollisionMessage contains data about the collision which an be used similar to a normal collision.&#x20;

```csharp
public struct ProjectileCollisionMessage
{
    public Projectile projectile;
    public Collider collider;
    public Vector3 point;
    public Vector3 normal;
    public Vector3 incomingDirection;
    public float distance;
}
```

{% hint style="success" %}
You will need to write a custom handler that implements `IProjectileFactoryCollisionReceiver`, or add the interface to an existing class. Then you can choose what to do with it.
{% endhint %}

## Example Implementation

In the [**Juicy Actions Integration**](https://infinitypbr.gitbook.io/magic-pig-games/juicy-actions/integrations/projectile-factory) for <mark style="color:blue;">Projectile Factory</mark>, the <mark style="color:$primary;">cubes</mark> and <mark style="color:$primary;">spheres</mark> are basic objects without any fancy `actor` type class on them. Since each demo projectile has differnet collision behaviors, we want the <mark style="color:$primary;">sphere</mark> and <mark style="color:$primary;">cube</mark> to react properly.&#x20;

```csharp
public class ProjectileFactoryCollisionHandler : MonoBehaviour, IProjectileFactoryCollisionReceiver
{
    public ActionOnPhysicsEvent actionOnPhysicsEvent;
    
    public void OnProjectileFactoryCollisionEnter(in ProjectileCollisionMessage message) 
        => actionOnPhysicsEvent.HandleTriggerEnter(null);

    private void OnValidate()
    {
        if (actionOnPhysicsEvent == null)
            actionOnPhysicsEvent = GetComponent<ActionOnPhysicsEvent>();
    }
}
```

In this class, which ships with the integration package, we call `HandleTriggerEnter(null)` when the `OnProectileFactoryCollisionEnter` event is received. This calls the `OnEnter` actions.

Note that to make this work the projectiles must have the option enabled to send this data, and the `ActionOnCollision`, `ActionOnTrigger`, or `ActionOnPhysicsEvent` components must allow `null` colliders.

{% hint style="info" %}
In your custom handling, you can make use of the `ProjectileCollisionMessage` data. This example does not.
{% endhint %}

<div><figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FGfoLfg9aRtKyjcwB01nt%2FScreenshot%202025-12-30%20at%202.32.01%E2%80%AFPM.png?alt=media&#x26;token=b44b4fb4-8021-4314-9669-d1cae47511a8" alt=""><figcaption></figcaption></figure> <figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FbPE3F5B6CrpifFbmBUkw%2FScreenshot%202025-12-30%20at%202.32.20%E2%80%AFPM.png?alt=media&#x26;token=9c1d5d0f-5379-42ce-b9c2-71dd1c95c300" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2431624982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MY3N_li2jPq7az6mYfq%2Fuploads%2FDqbYhNU0yWhhemT5hrB0%2FScreenshot%202025-12-30%20at%202.44.51%E2%80%AFPM.png?alt=media&#x26;token=aa579121-d3e8-4342-8943-f50ca96f69c0" alt="" width="563"><figcaption></figcaption></figure>

With those set, our <mark style="color:$primary;">sphere</mark> and <mark style="color:$primary;">cube</mark> objects now have <mark style="color:yellow;">Juicy Actions</mark> when they're hit by *any* projectile.
