OnSet system will be triggered twice if reuse an entity ID
eziasolsky opened this issue · comments
Describe the bug
OnSet system will be triggered twice if reuse an entity ID
To Reproduce
with flecs 2.4.8. this is the modified "example cpp simple_system".
`
#include <simple_system.h>
#include
struct Message {
const char* text;
};
int main(int argc, char* argv[]) {
flecs::world ecs(argc, argv);
flecs::entity Likes = ecs.entity();
ecs.system<Message>()
.kind(flecs::OnSet)
.each([](Message& messages) {
std::cout << messages.text << std::endl;
});
flecs::entity Apple = ecs.entity().set<Message>({ "Apple" });
flecs::entity Bob = ecs.entity().add(Likes, Apple);
Bob.destruct();
Apple.destruct();
ecs.progress();
flecs::entity Orange = ecs.entity().set<Message>({ "Orange" });
return 0;
}
`
Expected behavior
expects
Apple Orange
but got
Apple Orange Orange
This issue has been fixed in v3.0 (master). Bugfixes are no longer backported to v2.4.8 as the internals have changed too much, so I recommend upgrading. I added this to the list of known issues of 2.4.8.
I do still accept PRs for 2.4.x, if you want to contribute a fix I'll merge it and create a new release. Closing the issue for now as it has been fixed in newer releases.
I tried the same code with v3.0, but the system is not triggered at all.
In the v3 API you need to use a flecs::observer
instead of a flecs::system
. Try this code:
ecs.observer<Message>()
.event(flecs::OnSet)
.each([](Message& messages) {
std::cout << messages.text << std::endl;
});