Spawning an entity with minetest.add_entity seems like a game of chance. You never know whether the entity will actually spawn. Actually, it does always spawn, but there's a chance it is immediately removed afterwards. So the return value of minetest.add_entity is useless. This is one of the most frustrating bugs when you have to work with entities in a game and you absolutely must ensure the spawning of an entity. See
https://github.com/minetest/minetest/issues/4759
Entity spawning is only reliable when it's close enough to players, not on an arbitrary map position.
But I think I have finally discovered a very simple workaround!
Right before you call minetest.add_entity, you call minetest.load_area in a small area that includes the entity position before. Like so:
Code: Select all
local pos = vector.new(0,0,0)
local offset = vector.new(2,2,2)
minetest.load_area(vector.subtract(pos, offset), vector.add(pos, offset))
minetest.add_entity(pos, "example:my_entity")
I'm not 100% sure if this is 100% reliable, but it allowed me to fix some bugs with parachute spawning in Repixture.