Disappearing units (biters)

Place to get help with not working mods / modding interface.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Disappearing units (biters)

Post by PFQNiet »

I noticed that biters I placed in my mod disappeared after a while.

For reference, I have already set the biter's AI settings to not allow destroy when commands fail, but that shouldn't matter anyway since I'm manually giving them wander and go_to_location commands periodically to have them patrol the area.

After some logging and testing, I found that after 20 minutes (give or take a few ticks), the biters start vanishing, one by one, one every tick until they're all gone, without apparent regard for when they were created.

I then went back to my totally vanilla Factorio installation and tested there:

1. Open the Map Editor and create a New Scenario (it works in a "real" game too but this is easier for testing)
2. In the console, run:

Code: Select all

/c local e = game.surfaces.nauvis.create_entity{name="big-biter",position={0,0},force="neutral"}; e.set_command{type=defines.command.wander,radius=20}
3. Use the Time controls to skip ahead 20 minutes
4. Biter vanishes!

Do units have a time-to-live that I'm just unaware of or is this a bug?
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4055
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Disappearing units (biters)

Post by boskid »

There is a piece of logic to destroy wandering units after 20 minutes (2*max_group_gathering_time) when quite a lot of conditions are met:
- AISettings::allow_try_return_to_spawner is set to true
- unit has no spawner
- unit is wandering (simple command or compound with a single command)
- there are no spawners in a range of 5 chunks from the position the unit is in (if there would be, unit would set new spawner)
- 20 minutes (2*max_group_gathering_time) passed from leaving a spawner

Every of those conditions can be made to fail to prevent units from being destroyed. For example you can set a compound command containing compound command containing wander (2 layers of compound will bypass the "just wandering" check), or you can set allow_try_return_to_spawner to false or increase max_group_gathering_time.

Code: Select all

/c game.player.selected.set_command{type=defines.command.compound, structure_type=defines.compound_command.logical_or, commands={{type=defines.command.compound, structure_type=defines.compound_command.logical_or, commands={{type=defines.command.wander}}}}}
All of those feel like a little hack so feel free to open an interface request.
PFQNiet
Filter Inserter
Filter Inserter
Posts: 290
Joined: Sat Sep 05, 2020 7:48 pm
Contact:

Re: Disappearing units (biters)

Post by PFQNiet »

Oh, my mod removes spawners and manually spawns in enemies so that's fine. I can just set "allow_try_return_to_spawner = false" on the prototype and boom problem solved.

After a quick test, 80k ticks later and sure enough the biters have not disappeared. Thank you so much, I was up all night trying to figure this one out!
Andreman
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Mar 03, 2022 10:57 pm
Contact:

Re: Disappearing units (biters)

Post by Andreman »

I downloaded this scenario (viewtopic.php?f=36&t=85746), played a bit and get that issue - spitters disappears after some time. I tried to modify control.lua file of scenario, adding there "allow_try_return_to_spawner = false":

Code: Select all

local handler = require("event_handler")
handler.add_lib(require("freeplay"))
handler.add_lib(require("silo-script"))

script.on_init(function()
  allow_try_return_to_spawner = false
end)
And used command /c game.speed = 120 in restarted scenario. Spitters are still disapperaing, seems without timing consistancy

Also i checked variable value through command in-game: /c game.print(allow_try_return_to_spawner) , and it surprisingly returned nil in console.
Then i tried to change this variable in-game: /с allow_try_return_to_spawner = false
I checked - print in console now returned false. I made time faster and... spitters are still disappearing

What i am doing wrong? It's sad that scenario is not the same as intended
User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 4055
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Disappearing units (biters)

Post by boskid »

Andreman wrote: Thu Mar 03, 2022 11:51 pm
allow_try_return_to_spawner is NOT a free standing variable you could modify with 1 line in control.It is field of the LuaAISettings which you can obtain by reading LuaEntity::ai_settings. That means you would need to listen for many lua events to catch when units are being created and change this for them as they appear. You should be able to change this more easily through data stage since a UnitPrototype's ai_settings where you can set the initial value of allow_try_return_to_spawner.
Andreman
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Mar 03, 2022 10:57 pm
Contact:

Re: Disappearing units (biters)

Post by Andreman »

boskid wrote: Fri Mar 04, 2022 6:47 am
Thanks for answer, i could not find how i can access 'allow...' variable. I just not familiar with Factorio modding staff, never used it before.
So, all this means i need to create mod for changing this setting for this scenario?
In data.lua write something like that?:

Code: Select all

data.raw["unit"].ai_settings.allow_try_return_to_spawner = false
Or... i see another field there 'destroy_when_commands_fail' - maybe this is what i am looking for? But Prototype overview page says that both of this variables already false by default. I am a bit confused
Andreman
Manual Inserter
Manual Inserter
Posts: 3
Joined: Thu Mar 03, 2022 10:57 pm
Contact:

Re: Disappearing units (biters)

Post by Andreman »

So, i made a mod with data.lua containing this:

Code: Select all

data.raw["unit"]["small-biter"].movement_speed = 0.01
data.raw["unit"]["small-spitter"].movement_speed = 0.01

data.raw["unit"]["small-biter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["medium-biter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["big-biter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["behemoth-biter"].ai_settings.allow_try_return_to_spawner = false

data.raw["unit"]["small-spitter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["medium-spitter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["big-spitter"].ai_settings.allow_try_return_to_spawner = false
data.raw["unit"]["behemoth-spitter"].ai_settings.allow_try_return_to_spawner = false


data.raw["unit"]["small-biter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["medium-biter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["big-biter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["behemoth-biter"].ai_settings.destroy_when_commands_fail = false

data.raw["unit"]["small-spitter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["medium-spitter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["big-spitter"].ai_settings.destroy_when_commands_fail = false
data.raw["unit"]["behemoth-spitter"].ai_settings.destroy_when_commands_fail = false
And it works when i start new freeplay, i can see it by speed change. But when i start scenario i mentioned earlier, speed and disapperaring after time are still the same. So, this method not works for my purpose. I think i need to handle some runtime events as boskid wrote, but i dont know which of them https://lua-api.factorio.com/1.1.0/events.html.
Only on_entity_cloned and on_entity_spawned seems to be what i am looking for, but i am not sure
Post Reply

Return to “Modding help”