Bevy ECS structure

so i have a question regarding using ecs. how do you directly manipulate data inside an entity? right now i create a component with handles to stuff inside entity and manipulate by querying the component. is this correct strategy.

for example look at the mesh handles here. i spawn an entity (a mesh) with component that has same mesh handle and manipulate it there

example

Data lives in the components, not the entity. Entity is only a grouping of components used to find related components.

A close analogy to ECS is a relational database (SQL). Entity is the row, and the components are columns. You use queries to find which rows (entities) to update, and modify data in the columns (components).

2 Likes

I guess you wanted to write "(components)" thereo

1 Like

If it helps, you can think about the component as effectively being fields on the entity. When you iterate a Query<&CircleMesh>, you're asking to iterate over (just the one field of) each entity which has a CircleMesh field.

You could hold the Mesh as a direct member of CircleMesh, if you wanted, but by going through the asset loader/handle, you permit multiple entities to share the same Mesh data. Since you're using a dynamic mesh here, that sharing isn't used, but you're still sharing with other code that works with meshes, which goes through the asset loader in order to support that sharing.

In this case, since the entity already has a Mesh2dHandle(Handle<Mesh>) component as part of the material bundle, you don't need to store the handle again as part of your CircleMesh. Instead, use Query<(&CircleMesh, &Mesh2dHandle)> to grab both the "CircleMesh field" and the "Mesh2dHandle field".

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.