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

Entity spawned in on_step not visible to get_objects_inside_radius #14614

Open
sfan5 opened this issue May 5, 2024 · 2 comments
Open

Entity spawned in on_step not visible to get_objects_inside_radius #14614

sfan5 opened this issue May 5, 2024 · 2 comments
Labels
Bug Issues that were confirmed to be a bug Low priority Regression Something that used to work no longer does. @ Server / Client / Env.

Comments

@sfan5
Copy link
Member

sfan5 commented May 5, 2024

Minetest version

Minetest 5.9.0-dev 3017b02 (Linux)

Summary

#13880 causes objects spawned during iteration of the object list (so during on_step) to only show up once this iteration ends.
This could be considered a defect. It's not easily fixable.

Steps to reproduce

core.register_entity("test2:a", {
	initial_properties = {
		static_save = false,
		visual = "sprite",
		textures = {"cdb_update.png"},
	},
	on_step = function(self)
		local pos = self.object:get_pos()
		if not self.once then
			local obj = core.add_entity(pos, "test2:b")
			assert(obj ~= nil)
			for _, obj2 in ipairs(core.get_objects_inside_radius(pos, 1)) do
				if obj2:get_luaentity() and obj2:get_luaentity().name == "test2:b" then
					print("found it")
				end
			end
		end
		self.once = true
	end,
})
core.register_entity("test2:b", {
	initial_properties = {
		static_save = false,
		visual = "sprite",
		textures = {"cdb_add.png"},
	},
})
  1. do /spawnentity test2:a
  2. observe that both entities were spawned
  3. look for "found it" line in vain

bonus:
4. change on_step to on_activate
5. re-do and observe that "found it" was printed

@sfan5 sfan5 added Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible @ Server / Client / Env. Regression Something that used to work no longer does. labels May 5, 2024
@sfan5 sfan5 changed the title Entity spawned in on_step not visible to get_objects_inside_radius Entity spawned in on_step not visible to get_objects_inside_radius May 5, 2024
@SmallJoker SmallJoker added Bug Issues that were confirmed to be a bug and removed Unconfirmed bug Bug report that has not been confirmed to exist/be reproducible labels May 5, 2024
@nerzhul
Copy link
Member

nerzhul commented Jun 11, 2024

if i remember entities are activated asynchronously, when you are in on_step there are no activated yet, which require a full environment::step core side
on_activate "workaround" is logical, as you are setting the subcreation during the activation phasis

here is a short engine algo showing you why you have this behaviour

for Environment::step {
for new objs {
newobj->activate()
}

for enabled_objs {
obj->step ()
}
}

@sfan5
Copy link
Member Author

sfan5 commented Jun 11, 2024

No, that's not it. Objects are directly activated here:

// Post-initialize object
// Note that this can change the value of isStaticAllowed() in case of LuaEntitySAO
object->addedToEnvironment(dtime_s);

It's due to the newly introduced data structure acting this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug Low priority Regression Something that used to work no longer does. @ Server / Client / Env.
Projects
None yet
Development

No branches or pull requests

3 participants