-
Notifications
You must be signed in to change notification settings - Fork 2
IPhantomComponent
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
Phantomcomponent attached -
Entity.IsAlivereturnsfalse -
Entity.IsPhantomreturnstrue - Automatically excluded from all queries
- Use
Include<Phantom>to include phantoms
- Use
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.
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.