Skip to content

Commit acc3819

Browse files
authored
Fixed a case where a remove event would be sent even the component add happened in the same execution tick (#41)
1 parent de7a389 commit acc3819

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

ecsact/entt/detail/system_execution_context.hh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ struct system_execution_context : system_execution_context_base {
175175
if constexpr(!C::transient) {
176176
if(info.registry.template all_of<component_added<C>>(entity)) {
177177
info.registry.template remove<component_added<C>>(entity);
178+
info.registry.template remove<component_removed<C>>(entity);
179+
} else {
180+
info.registry.template emplace_or_replace<component_removed<C>>(entity);
178181
}
179182
if constexpr(!std::is_empty_v<C>) {
180183
auto& temp = info.registry.template storage<temp_storage<C>>();
@@ -191,10 +194,6 @@ struct system_execution_context : system_execution_context_base {
191194
// TODO(zaucy): Look into if emplace_or_replace is necessary instead of
192195
// just replace.
193196
info.registry.template emplace_or_replace<pending_remove<C>>(entity);
194-
195-
if constexpr(!C::transient) {
196-
info.registry.template emplace_or_replace<component_removed<C>>(entity);
197-
}
198197
}
199198

200199
void remove(ecsact_component_like_id component_id) {

ecsact/entt/trivial_system_impl.hh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,13 @@ void trivial_system_impl(
8585
info.registry.template emplace<pending_remove<C>>(entity);
8686

8787
if constexpr(!C::transient) {
88-
info.registry.template emplace<component_removed<C>>(entity);
88+
if(info.registry.template all_of<component_added<C>>(entity)) {
89+
info.registry.template remove<component_added<C>>(entity);
90+
info.registry.template remove<component_removed<C>>(entity);
91+
} else {
92+
info.registry.template emplace_or_replace<component_removed<C>>(entity
93+
);
94+
}
8995

9096
if constexpr(!std::is_empty_v<C>) {
9197
auto& temp = info.registry.template storage<temp_storage<C>>();

0 commit comments

Comments
 (0)