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})
		local equips = nina:add_component('stonehearth:equipment')
		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…


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.


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