Entity is spawning with no a.i

I have this code that when I run it in Lua console, it works perfectly. The entity is spawned, equipped, etc… and it moves and attacks my guys, etc… Fine.

		local nina = radiant.entities.create_entity("swamp_goblins:humans:nina", {owner = ctx.npc_player_id})
		nina:get_component('stonehearth:job'):promote_to("stonehearth:jobs:footman")
		local equips = nina:add_component('stonehearth:equipment')
		equips:equip_item("stonehearth:trapper:knife")
		equips:equip_item("/stonehearth/jobs/cleric/cleric_abilities/cleric_abilities.json")
		radiant.terrain.place_entity(nina, ctx["firefly_human_encounter"].boss_location)

Now, the exact same code, with not a single character difference, but run from a campaign script instead of console, it does not work! The character is spawned but has no a.i., the only movement he does is the idle breath (because it was set in the json) but it is not even idle, as it has no a.i. Opening the ai debug view it is empty, no idle, no top, etc…

Why?

1 Like

I don’t know the full cause, but I experienced this same issue when trying to script some monsters spawning in SH:TD. The normal monster spawning via the wave controller was working fine, but I think the ants spawning from killing beetles, and actually spawning the path previewer entities, resulted in them having no AI. I think it’s some sort of threading issue, perhaps related to when/where in the “stack” events are handled. The way I worked around it was setting a timer or using radiant.on_game_loop_once to delay and shift the “source” of the spawn call.

4 Likes

thanks. I will try that too
Edit: It worked, thanks!

3 Likes