-
I started by writing something like this: ecs.system<Body, Position>("PositionSystem")
.kind(flecs::OnUpdate)
.each([](Body& bodyC, Position& positionC) {
auto position = bodyC.BBody->GetPosition();
positionC.Position = {position.x, position.y};
}); However I noticed that all entities instantiated from a prefab were sharing the same components. Should I instead use ecs.system<Body, Position>("PositionSystem")
.kind(flecs::OnUpdate)
.each([](flecs::entity& entity, Body& bodyC, Position& positionC) {
auto position = bodyC.BBody->GetPosition();
entity.set<Position>({position.x, position.y});
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I believe you could add Or what I think might also work is to make sure the position term is marked with I remember |
Beta Was this translation helpful? Give feedback.
I believe you could add
AlwaysOverride
toPosition
to ensure an instantiated prefab gets its own copy of aPosition
component.Or what I think might also work is to make sure the position term is marked with
out
orinout
to ensure writes go to its own copy, not the shared component. I believe in C++ that would look something like.term_at(2).inout()
. (Or.term_at(1)
in Flecs v4, since they'll be zero-indexed going forward.)I remember
inout
is the default for owned components, butin
is the default for shared / inherited components. Though unsure how that's supposed to make sense for components that aren't defined asconst
in the system.