From 5e3739036a792348e25761da9a8d5aff140a6e2c Mon Sep 17 00:00:00 2001 From: Intrinsic <96358358+Intrinsic-zyx@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:46:14 -0800 Subject: [PATCH] Fixed hooks invocation in the event of relationship target deletion. (#179) * Fixed hooks invocation (case #3) * Reverted world:component() to world:entity() Co-authored-by: lolmanurfunny <77128366+lolmanurfunny@users.noreply.github.com> * Removed whitespace --------- Co-authored-by: lolmanurfunny <77128366+lolmanurfunny@users.noreply.github.com> --- jecs.luau | 2 +- test/tests.luau | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/jecs.luau b/jecs.luau index d8ec188..d80cd00 100644 --- a/jecs.luau +++ b/jecs.luau @@ -1158,7 +1158,6 @@ do local idr_t_archetype = archetypes[archetype_id] local idr_t_types = idr_t_archetype.types - local on_remove = idr_t.hooks.on_remove for _, child in idr_t_archetype.entities do table.insert(children, child) @@ -1180,6 +1179,7 @@ do end break else + local on_remove = id_record.hooks.on_remove local to = archetype_traverse_remove(world, id, idr_t_archetype) if on_remove then for _, child in children do diff --git a/test/tests.luau b/test/tests.luau index 1842975..d7bec16 100644 --- a/test/tests.luau +++ b/test/tests.luau @@ -1699,6 +1699,25 @@ TEST("world:delete() invokes OnRemove hook", function() world:delete(B) + CHECK(called) + end + do CASE "#3" + local world = world_new() + local pair = jecs.pair + + local viewingContainer = world:entity() + local character = world:entity() + local container = world:entity() + + local called = false + world:set(viewingContainer, jecs.OnRemove, function(e) + called = true + end) + + world:add(character, pair(viewingContainer, container)) + + world:delete(container) + CHECK(called) end end)