Skip to content

Commit

Permalink
Fixed hooks invocation in the event of relationship target deletion. (#…
Browse files Browse the repository at this point in the history
…179)

* Fixed hooks invocation (case #3)

* Reverted world:component() to world:entity()

Co-authored-by: lolmanurfunny <[email protected]>

* Removed whitespace

---------

Co-authored-by: lolmanurfunny <[email protected]>
  • Loading branch information
Intrinsic-zyx and lolmanurfunny authored Jan 17, 2025
1 parent 0296c4b commit 5e37390
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jecs.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/tests.luau
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5e37390

Please sign in to comment.