@resin_smoker
The mod is AI Wave Survival. The script can spawn hundreds to thousands of units per wave, so the error shows for any type of units that can be spawned in a wave. I played one game that had over 8000 such errors before crashing after 1 hour in.
The spawn script first runs
unit = aiBrain:CreateUnitNearSpot(rspawn, posX, posZ)
It checks if the unit was created, and if not, tries again using
unit = CreateUnitHPR(rspawn, aiBrain:GetArmyIndex(), posX, terrainAltitude, posZ, 0, 0, 0)
It then checks if the unit exists with the following code, before modifying things like the units health, veterancy, and damage.
if unit and unit ~= nil and not unit.Dead then
It then runs an attack script for each unit, which chooses a random target from a list, and issues orders where:
pUnit = Random Target
aUnit = Spawned Unit
local pUnit = nil
if Random(1, 3) <= 2 then
if Random(1, 2) == 1 then
pUnit = RandomEnemyUnitsLandDefenseList(self)
else
pUnit = RandomEnemyUnitsLandEconomyList(self)
end
else
if Random(1, 3) == 1 then
pUnit = GetClosestEnemyNearAntiNavy(self, aUnit)
else
pUnit = RandomEnemySubsForAntiNavyList(self)
end
end
if pUnit and not pUnit:BeenDestroyed() then
IssueClearCommands({ aUnit })
local VECTOR3
local pUnitPos = pUnit:GetPosition()
if Random(1, 8) <= 6 then
IssueMove({ aUnit }, pUnitPos)
else
if Random(1, 4) <= 3 then
IssueMove({ aUnit }, pUnitPos)
WaitSeconds(Random(20, 60))
IssueClearCommands({ aUnit })
end
IssueAggressiveMove({ aUnit }, pUnitPos)
WaitSeconds(Random(48, 78))
repeat
WaitSeconds(12)
if aUnit:BeenDestroyed() or pUnit:BeenDestroyed() then
break
end
if Random(1, 12) == 6 then
break
end
until pUnit:BeenDestroyed() or pUnit == nil
WaitTicks(20)
if aUnit ~= nil and not aUnit:BeenDestroyed() then
IssueClearCommands({ aUnit })
end
end
end
Actually writing out all the code, it looks like the error might be from having orders issued to units that may already be dead, as I forgot to add checks for when I have a delayed order.
And what would be a faster way to check if a unit is dead or not, if I wanted to optimize the code a little?