Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnSet system will be triggered twice if reuse an entity ID #701

Closed
ghost opened this issue Apr 11, 2022 · 3 comments
Closed

OnSet system will be triggered twice if reuse an entity ID #701

ghost opened this issue Apr 11, 2022 · 3 comments

Comments

@ghost
Copy link

ghost commented Apr 11, 2022

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

@ghost ghost added the bug Something isn't working label Apr 11, 2022
@SanderMertens
Copy link
Owner

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.

@ghost
Copy link
Author

ghost commented Apr 11, 2022

I tried the same code with v3.0, but the system is not triggered at all.

@SanderMertens
Copy link
Owner

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;
        });

@SanderMertens SanderMertens removed the bug Something isn't working label Aug 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant