Skip to content

IPhantomComponent

Martin Evans edited this page Apr 23, 2025 · 8 revisions

A phantom component is a component defined with IPhantomComponent instead of IComponent.

public interface IPhantomComponent : IComponent;

When an Entity with any phantom components would be destroyed it becomes a phantom. Phantom entities:

  • Have a Phantom component attached
  • Entity.IsAlive returns false
  • Entity.IsPhantom returns true
  • Automatically excluded from all queries
    • Use Include<Phantom> to include phantoms

A phantom entity can be destroyed in two ways:

  • Explicitly delete it again.
  • Remove all components which implement IPhantomComponent.

A phantom component is useful when you need to remove an entity from the world, but keep some information about it. For example when a character in a game is killed it could become a phantom. This would immediately exclude it from all game systems - freezing it in place at the instant of death.

IPhantomNotifierComponent

To receive a callback when an entity first becomes a phantom, implement IPhantomNotifierComponent:

public interface IPhantomNotifierComponent : IComponent
{
    void OnBecomePhantom(EntityId self);
}

OnBecomePhantom is called just once when the entity first becomes a phantom. It is passed the ID of the Entity it is attached to.

Clone this wiki locally