Is having multiple for loops for iterating through the components in 'view' or a 'group', wrong thing to do? #681
-
So I'm fairly new to entt and was using entt mostly through trial and error. So In my use case, I have something like this: `
Where I am iterating through a group twice, since I need certain things to be sandwiched between the begin/end scenes of the separate renderers. I am not getting anything rendered with code above. It works fine for either 'cube' or 'sprite' if I do (the following) where I just extract one component but not both at the same time: `
Originally I was creating 2 differrent groups (like shown below) in different scopes but that gave me a weird runtime error. `
I guess my questions mainly boil down to 3 things:
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Do your entities have both components at the same time? If not then having the group constructed the way you do in the first snippet is incorrect - |
Beta Was this translation helpful? Give feedback.
-
You can. There is nothing wrong in it. Though, without a reproducible example, it's impossible to tell you what's weong in what you're doing.
It's the other way around. You cannot own the same component: auto group = m_Registry.group<SpriteRendererComponent>(entt::get<TransformComponent>);
auto group2 = m_Registry.group<CubeRendererComponent>(entt::get<TransformComponent>); Or even: auto group = m_Registry.group<SpriteRendererComponent, TransformComponent>();
auto group2 = m_Registry.group<CubeRendererComponent>(entt::get<TransformComponent>); And so on.
An alternative to what exactly? You can use views and probably you should do it until you measure and find that there is a bottleneck to justify the use of a group. Other than this, as I said above, withou a self-contained snippet that explains what you're trying to do it's hard to tell what an alternative is for that. 🤷♂️ |
Beta Was this translation helpful? Give feedback.
You can. There is nothing wrong in it. Though, without a reproducible example, it's impossible to tell you what's weong in what you're doing.
It's the other way around. You cannot own the same component:
Or even: