Question about component based architecture

Godot Version

Godot 4.3

Question

I am working on a basic enemy, and I want to use components to make future enemies easier to make (think MovementComponent, VisualComponent, HurtboxComponent, HealthComponent etc.).

My question is, is it better for these components to communicate trough signals directly?
(HurtboxComponent has been hit and sends a “HasBeenHit” signal. HealthComponent listens and reduces damage, VisualComponent plays a “Hit” animation, MovementComponent applies knockback and so forth)

Or it is better to have some sort of EntityManager that listens to signals from its children components?
(HurtboxComponent has been hit and sends a “HasBeenHit” signal. EntityManager listens, and calls ApplyDamage on HealthComponent, PlayHitAnimation on VisualComponent, ApplyKnockback on MovementComponent and so forth)

this, Signals directly sounds better to me. Easier to plug-and-play through the editor.

1 Like

I agree with gertkeno above.

Your choice is signals, or entity manager. But I see these for two different roles.

Signals for local communication between local components as you described.

The entity manager is for non-local communication for complex interactions across multiple entities and scenes on a more global scale.

Using both is the real answer to keep your components and entities as encapsulated and truly modular as possible. So use both :slight_smile:

1 Like