0
\$\begingroup\$

I would like to implement something similar discussed in Efficient communication between entities using ECS via entt

There are two entities Ship, Engine. Ship has the components AppliedForces, Mass and Velocity. Engine has the components Parent and Thrust and Parent is a component containing an id of the engine. The parent component is used as follows:

 auto view = entities.view<Thrust, Parent>(); auto& applied_forces = entities.get<AppliedForces>(parent.id); 

How do I get the the id of an Entity (Engine in this context) in EnTT in order to retrieve components of an entity itself using the id?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

When you prepare a view in EnTT, it allows you to iterate over all the Entities that fulfil that particular criterion (in your case, entities that have the Thrust and Parent components).

The view also retrieves non-empty components for you so you don't have to do a get operation while in a view (at least on the components you already setup the view with).

In your case, you would want to do something like this:

entities.view<Thrust, Parent>().each( [&](entt::entity engine, Thrust& thrust, Parent& parent) { /* do something here with the Engine entity */ }); 

If you have multiple engines, the view will iterate over all the engine entities.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.