Jump to content
grandelemental

Problem with "infinite" spawning

Recommended Posts

So I've been trying to work with a SP mission that keeps a certain amount of hostile AI units spawned in a map, kind of like the old Flashpoint dynamic missions for Arma 2 but obviously much, much simpler. Every time a unit is killed, a new one spawns, keeping the amount of units constant (test value has been 15, and that includes the player as well). The problem is that after about ~150 spawns, they just stop spawning. I've tried all kinds of alternative solutions but can't quite work out why this keeps happening. I've had a while true loop to spawn units only, if the unit limit isn't reached, and if it is, just sleeping a couple of seconds. I've tried adding an event handler "killed" so that when a initially spawned unit dies, it immediately respawns a new unit. But no matter how I try to accomplish this, after a unit has been spawned around 150 times, the script just doesn't spawn anything.

Everything seems to point into a some kind of limit with either event handlers (I have no idea if they get deleted when the unit they are assigned to dies) or dynamically named groups. Is there a way to completely remove a unit with ALL parameters and allocations assigned to it (like group names and such), so that it won't fill up the space? It's a longshot, but I've honestly no idea what causes this, how to fix it, or whether it's even possible. =(

 

Share this post


Link to post
Share on other sites

There's a hard coded limit of 144 groups and I think that is your problem here. To check if this is the issue, could you run the following once you notice that the AI have stopped spawning:

 

hint format["# groups: %1", count(allGroups)];

 

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, dchan200 said:

There's a hard coded limit of 144 groups and I think that is your problem here. To check if this is the issue, could you run the following once you notice that the AI have stopped spawning:

 


hint format["# groups: %1", count(allGroups)];

 


Yeah, this was it! I completely misunderstood how ArmA handles groups beneath the surface, I assumed that the empty groups would be automatically deleted and their resourced could be reallocated. Now I get around this problem by just spawning some static groups and refilling them when the units are all killed.

Thanks a lot mate!

Share this post


Link to post
Share on other sites
2 minutes ago, grandelemental said:


Yeah, this was it! I completely misunderstood how ArmA handles groups beneath the surface, I assumed that the empty groups would be automatically deleted and their resourced could be reallocated. Now I get around this problem by just spawning some static groups and refilling them when the units are all killed.

Thanks a lot mate!

Glad it worked for you.

 

Just to note, another approach to handling this problem is by periodically removing the empty groups yourself:

 

while {true} do
{
    {
        if (count(units(_x)) == 0) then
        {
            deleteGroup(_x);
        };

    } forEach allGroups;

    sleep 60;
}

I have not tested the code above, but I think it should work.

 

Share this post


Link to post
Share on other sites

Just use the Killed EH. Either respawn units into the group of the killed unit OR delete the group and create a new one.

e.g place this in a gameLogic

h = this  spawn {
	_numActiveUnits = 15;
	
	TAG_fnc_spawnUnit = {
		params[ "_pos", "_type", "_group" ];
		
		_unit = _group createUnit [ _type, _pos, [], 0, "FORM" ];
		_group addWaypoint[ [0,0,0], 0 ];
		_unit setVariable[ "spawnPos", _pos ];
		
		_unit addEventHandler [ "Killed", {
			params[ "_killed" ];
			
			_pos = _killed getVariable "spawnPos";
			_type = typeOf _killed;
			_side = side group _killed;
			deleteGroup group _killed;
			[ _pos, _type, createGroup _side ] call TAG_fnc_spawnUnit;
		}];
	};
	
	for "_i" from 1 to _numActiveUnits do {
		[ getPos _this, "B_Soldier_F", createGroup west ] call TAG_fnc_spawnUnit
	};
};

 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×