AIWaveAddUnit(wave w, unit u) does not work

Besides numerous bugs I encountered, I have found circumventions most of the time. But this time, I really could not find a way:

AIWaveAddUnit(wave w, unit u) simply does not work. (after having started the AI in campaign mode)

The unit will not get added to the wave after calling, and that is simply verified by the fact that they will not be issued any orders, also that if you check the wave of the unit it is still of value “No Wave” and also if you check the wave variable, its unit group is still “No Group”.

If anyone cares, I can share a test map which shows this. (Unfortunately i cannot provide a link here)

You can by putting it between ```, ```your text``` becoming your text.

https://filetransfer.io/data-package/Wf0aqkoo#link

ok, so here you can download the map. Open it in the SC2 Editor and use Test Document.

What should happen is that the 5 spawned Marines get merged with the AIs Main Wave (index 0) by using a merge wave with merge wave target. However the marines will neither get issued orders (to move to the main waves target which is somewhere near the beacon that is placed on the center of the AIs Main Town) nor have they become part of any wave as seen by the created Text Tag.

Can’t access it since it requires logging in with Google.
Have you tried checking in campaign maps where the command you use is used, and how it is used?
I tried a bit of that, loading a random WoL map, and while it was named “AIAttackWaveAddUnits4” instead, it felt like it was always eventually followed by “AIAttackWaveSend”, meaning a manual control.
Maybe you added the dependencies for the wrong campaign type (WoL/HoTS/LoTV/Coop/Other?) and are using things not compatible with each others?

AI is not my field, so I don’t know if I will be able to help much :turtle:

Oh sorry, will provide a different link soon. No I am using a different system. I am trying to use the same wave system that the Blizzard Melee AI uses, which is the “newer wave system” which is what you can find under AI Advanced Category.

https://filetransfer.io/data-package/Wf0aqkoo#link

I tried to look at the code of the map and…it’s hard to find what to say.
Is there something that actually work that you saw somewhere and tried to imitate?

Yes. Blizzards melee AI uses the same merge wave code when the AI gets a new unit. However thats besides the point, which is that the add unit to wave function simply does not add the unit to the wave as it should.

In case you wanted to take a look at it, its part of the MeleeAI.galaxy script.

//--------------------------------------------------------------------------------------------------
// AIMergeUnit
//--------------------------------------------------------------------------------------------------
void AIMergeUnit (int player, unit u, wave w) {
wave merge = AIWaveCreate(AIWaveInfoCreate(),
player, AIGetGatherLocation(player, c_townMain));
AIWaveAddUnit(merge, u);
AIWaveSetType(merge, c_waveStateMerge,
AIWaveTargetMerge(w));
}
//--------------------------------------------------------------------------------------------------
// AINewUnitDefault
//--------------------------------------------------------------------------------------------------
void AINewUnitDefault (int player, unit u) {
wave w = AIWaveGet(player, c_waveMain);
AIMergeUnit(player, u, w);
}

Ok I found the solution (albeit a stupid one).

If I put in a delay before I loop over the units and call the merge wave function for each unit of 1 seconds it works all of a sudden.

However, it will also work without delay if you call AISetIgnoredByWave(unit u, boolean b) with b=false before calling to add the unit to the wave.

Update: This will only work for the merge wave (when creating a new wave.) Still havent figured out why I can’t add directly to the existing waves)

In your example, if I used AIMeleeStart(2) (since I thought it’s a default for melee mod), the marines would move.

I ended up realizing that wasn’t what I was trying to do though…now that I’ve opened another map, what I was going for (and I’m going to test it now, though I don’t expect much to tell from it), was the usual init package:

        MeleeInitResources()
        MeleeInitUnits()
        MeleeInitAI()
        MeleeInitOptions()

I’m not sure if your “solution” is for your example or the “real thing”, but I don’t understand the whole picture enough to think of more.

edit: I don’t understand well enough what a conclusive test would be from this map lol

Yes but I dont want to use the melee AI. Of course this would work. I am using the campaign mode AI which you can use custom build orders with and more. I “fixed” my problem by deleting the existing wave (Wave Delete) (which I couldnt add to) and reassociating a newly created Wave with Wave Set.