0
\$\begingroup\$

Ive been building a game using a Entity Component system, but im having a bit of an issue finding a specific object in my entity system without knowing the Entity's Id.

My game is organized in Layers, with each layer owning its own set of systems, such as Entity System, Render System, Collision etc.

Right now, the game has two layers. The Game layer, which encapsulates all game objects and their data, and a Hud layer, which houses all the UI controls. (Pause, restart etc).

What I want to be able to do is, once a specific thing happens in the game layer, such as an enemy dying, I want to be able to communicate to the Hud layer to tell a button to appear or disable itself etc. The problem is, I have no way of finding that button because I have no Id to query for the button in the Hud layers entity system and the reference to the button gets lost after I create the button when the game starts up.

Ive looked into implementing a message queue type of thing, or using some sort of publish/subscribe pattern, but still the issue is how I can communicate that change to an object who's Id I dont know.

One solution I thought about is giving all UI Elements unique names. That way whenever I need to do a change in the UI, I can query the Hud Layer Entity System for an entity with that name, and get its reference back. But then that entirely ruins an entity having a unique Id, because it now relies on using a name for identification.

Is there any way I can get around this?

\$\endgroup\$
0

2 Answers 2

3
\$\begingroup\$

I think the Observer Pattern may fit here. Instead of sending a message to your button, let your button observe some component.

\$\endgroup\$
1
\$\begingroup\$

The game layer probably shouldn't know about the HUD layer. The HUD layer should maybe listen to events from the game layer.

Your example is a bit vague, so let's say there is a button above each enemy that should have the lifetime of the enemy. You could make a button system that checks that the corresponding enemy(a component of the button) is still alive.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .