How it works
A projectile is a prefab with a Projectile component on its root, a Rigidbody and usually a trigger collider, with your particle systems or meshes as children. The Projectile holds a ProjectileData asset (speed and damage), a Spawn Behavior and a list of behaviors. It raises lifecycle events for launch, collisions, triggers, destroy and pooling, and every behavior listens to them.
Behaviors are ScriptableObject assets, grouped as movement, collision, destroy, audio and trajectory (aim preview). At launch, each behavior asset is cloned for that projectile, so many projectiles can share one asset without sharing state. For example, a homing missile that explodes on impact takes three behaviors: HomingMovementBehavior, DestroyOnTriggerOrCollision and SpawnObjectOnDestroy set to your explosion prefab.
A ProjectileSpawner goes on whatever fires: a gun, wand, ship or turret. It keeps a list of projectile prefabs, a target, spawn points for multiple barrels, and a collision mask. From your player or NPC code:
SpawnProjectile() fires the active projectile
StopProjectile() stops a repeating or continuous shot
NextProjectile() and SetProjectile() switch projectiles
SetTarget() sets what homing and look-at behaviors aim at
The Spawn Behavior decides how a shot comes out (count, spread, pattern, delays and repeats). Spawn Behavior Modifications adjust each projectile before launch, such as giving a grenade physics velocity or spawning the shot on the target. For instant hits, RaycastShooter and its handlers drive hitscan guns and beams with line renderer visuals, and they raise the same collision events.
The spawner’s inspector has Runtime Test buttons to start and stop spawning and step through projectiles, and the Projectiles Quick Editor adds, removes or replaces behaviors on many projectiles at once.
Events, observers and pooling
To react to projectiles without changing their flight (for damage, score or camera shake), use:
- Observers on a spawner, copied to every projectile it fires
- ObserverObject and SpawnerObserverObject components that watch one projectile or spawner
- UnityEvents in the inspector
- FactoryManager global events such as
OnLaunchGlobal and CollisionEnterGlobal, for game-wide systems
Projectiles are pooled by default. With a Projectile Pool Manager in the scene, destroy behaviors return projectiles to the pool instead of destroying them.
Writing your own behaviors
When none of the behaviors we ship fits, subclass MovementBehavior, CollisionBehavior, DestroyBehavior, ProjectileObserver or another base class, and override only the events you need, such as LaunchProjectile, TriggerEnter or Tick (the projectile calls it every frame). Add [ShowInProjectileEditor] to a field to show it in the Projectile inspector. Subclass ProjectileData to calculate speed or damage from your own stats, or SpawnBehavior for custom fire patterns.
Pooled projectiles are reused, so reset per-shot values on launch and release anything you started when the projectile returns to the pool. The bundled AI skill follows these rules when it writes behaviors for you, and the scripting documentation has a page for each of these systems.