diff --git a/res/content/base/scripts/drop.lua b/res/content/base/scripts/drop.lua index ae61f963..3740cc0e 100644 --- a/res/content/base/scripts/drop.lua +++ b/res/content/base/scripts/drop.lua @@ -4,5 +4,6 @@ end function on_grounded() entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360)) + print(stdcomp) entity:despawn() end diff --git a/res/modules/internal/stdcomp.lua b/res/modules/internal/stdcomp.lua index fa1fc020..3316bae4 100644 --- a/res/modules/internal/stdcomp.lua +++ b/res/modules/internal/stdcomp.lua @@ -40,10 +40,6 @@ return { return entity end, remove_Entity = function(eid) - local entity = entities[eid] - if entity and entity.on_despawn then - entity.on_despawn() - end entities[eid] = nil; end } diff --git a/src/logic/scripting/scripting.cpp b/src/logic/scripting/scripting.cpp index 2925a553..2aa6c48f 100644 --- a/src/logic/scripting/scripting.cpp +++ b/src/logic/scripting/scripting.cpp @@ -296,8 +296,12 @@ static bool process_entity_callback( bool scripting::on_entity_despawn(const EntityDef& def, const Entity& entity) { const auto& script = entity.getScripting(); if (script.funcsset.on_despawn) { - return process_entity_callback(script.env, "on_despawn", nullptr); + process_entity_callback(script.env, "on_despawn", nullptr); } + auto L = lua::get_main_thread(); + lua::get_from(L, "stdcomp", "remove_Entity", true); + lua::pushinteger(L, entity.getUID()); + lua::call(L, 1, 0); return true; }