Projectile lifecycle
Creation and ownership
Section titled “Creation and ownership”Projectiles derive from Entity. Set their owner before adding them to the level so owner filtering and hit attribution are ready when the first tick runs. For a projectile that uses the common shoot helper:
var arrow = new ArrowEntity();arrow.SetOwner(shooter);arrow.SetPos(origin.X, origin.Y, origin.Z);
Projectile.SpawnProjectileUsingShoot( arrow, world, direction.X, direction.Y, direction.Z, pow: 1.5f, uncertainty: 0.0f);The helper calculates motion, updates projectile rotation, and calls ILevel.AddFreshEntity. A custom spawn method may be appropriate when launch motion or scene setup differs; follow nearby projectiles and keep its units explicit.
Tick and hit flow
Section titled “Tick and hit flow”Projectile.Tick updates owner-clearance checks and base entity timing. Concrete classes can add their own movement, gravity, inertia, or effect updates around that lifecycle. The base hit dispatcher selects an entity or block hook:
protected override void OnHitEntity(EntityHitResult hitResult){ base.OnHitEntity(hitResult); ApplyEffect(hitResult.Entity); Discard();}
protected override void OnHitBlock(BlockHitResult hitResult){ base.OnHitBlock(hitResult); // lets the hit block react to the projectile Discard();}The example assumes the subclass has an ApplyEffect method. Some projectiles intentionally survive a hit or have an effect-only block response, so make cleanup match the behavior you implement.
Before overriding Tick, inspect the chosen base class’s call order. Projectiles that implement their own movement still need owner checks, collision tracing, rotation, BaseTick, and hit dispatch in the correct order; copying only the movement lines can silently drop those behaviors.
Separate responsibilities
Section titled “Separate responsibilities”- The item or mob that launches the projectile chooses origin, direction, speed, and owner.
- The projectile owns movement, collision eligibility, and hit response.
- Damage/effect services own shared health and status rules.
- The level routes entity insertion and block-hit callbacks.
Do not put a projectile’s species-specific damage rule into WorldManager. Keep hit effects close to the projectile or a reusable damage/effect type.
Persistence and verification
Section titled “Persistence and verification”Not all projectiles are saved. If yours must survive unload or restart, add its fields to the entity save/load path and verify type reconstruction. Check removal when the owner disappears, collision with the owner on the first ticks, block hits, entity hits, leaving loaded columns, and lifetime expiration.
Related: adding an entity, entity simulation, and physics and collision.