Computer Opponents
A computer player is a Sein AI Controller Blueprint. The Game Mode spawns one for each AI slot and hands it a seat in the match. The controller reads the simulation and gives orders, and the orders cross the lockstep boundary exactly as a human’s do.
Only the host runs the AI. Because only the commands it issues are shared, its reasoning does not have to be deterministic. It can use floats, random numbers and anything else Blueprint offers. It must never write simulation state directly, only issue orders.
Goal. Build a small opponent that trains Soldiers, waits until it has six idle, and sends them at the nearest enemy. Then tune how often it thinks and how much it can see.
Before you start. You need a map with at least two Sein Player Starts, a Barracks whose Train Soldier ability exists (SeinARTS.Ability.Produce.Soldier), and Soldiers with Move and Attack. Add Victory, Defeat and an AI builds the same pieces for the demo and adds mining. This page shows the pattern on its own.
1. Create the controller
Section titled “1. Create the controller”In the Content Browser, create a Blueprint Class with parent Sein AI Controller and name it AIC_Skirmisher.
Open your Game Mode Blueprint and set AI Controller Class to AIC_Skirmisher. The Game Mode spawns one controller per AI slot and tells it which player it plays. The default class is the plain Sein AI Controller, which does nothing. With the class empty, AI slots get no controller, their units stand idle, and the log says so.
2. Put a computer in a slot
Section titled “2. Put a computer in a slot”- Playing a level directly. Select the Sein Player Start for the opponent and set Slot State to AI.
- From the lobby. The host sets a slot to AI in the lobby UI. The lobby can also pass an AI Profile tag, which is stored on the slot in the match settings, so a controller can read Get Match Settings and pick a personality.
3. Choose a think rate
Section titled “3. Choose a think rate”Add variables to AIC_Skirmisher:
| Variable | Type | Default |
|---|---|---|
ThinkEvery |
Integer, Instance Editable | 30 |
ArmySize |
Integer, Instance Editable | 6 |
Me |
Sein Player ID | |
Barracks |
Sein Entity Handle | |
IdleSoldiers |
Sein Entity Handle array | |
Enemy |
Sein Entity Handle |
Override On Sim Tick. It runs on the host every simulation tick, before that tick’s commands are processed. In a standalone game the commands you give apply on the same tick; in a network match they join the next lockstep turn. Doing real work on every tick is wasteful, so throttle it:
- Break Sein AI Tick Context. Set
Meto Owned Player ID. - Branch on Current Tick
%ThinkEveryequal to0. - On true, call
Scan World,Train, thenAttack, in order.
The simulation runs at 30 ticks a second by default. ThinkEvery of 30 means one decision a second. A larger number is a slower, easier opponent and costs less host time. 90 thinks once every three seconds.
4. Query the match
Section titled “4. Query the match”Scan World sorts what the AI knows:
-
Reset
BarracksandEnemy, and ClearIdleSoldiers. -
Query All Entities with an empty query, which matches everything, and Skip Abstract Entities on. For Each Loop over the result.
-
Switch on Get Entity Relation for the entity and
Me:- Friendly with the tag
SeinARTS.Unit.Barracks: store it inBarracks. - Friendly with
SeinARTS.Unit.Soldier: test Has TagSeinARTS.Ability. A unit with no ability tag has no order, so it is idle. Add it toIdleSoldiers. - Enemy: store the first one in
Enemy.
Friendly includes a teammate’s units. In a team game, also test that Get Entity Owner is
Me, because the AI may only command its own. - Friendly with the tag
Two queries are available, and the choice sets how fair the opponent is:
| Node | Sees |
|---|---|
| Query All Entities | Every entity, through the fog. A cheating, perfect-information opponent. |
| Query Visible Entities For Player | Only what the Observer Player can see through the fog. Pass Me as the Observer. |
Both take a Gameplay Tag Query; an empty query matches everything. To make an opponent that scouts, use the visible query, keep the last enemy it saw in a variable, and send a unit to look when it has seen none.
Reading the economy is also a query. Get Resource gives a balance, and Get Production Data on a building gives its queue.
5. Give orders
Section titled “5. Give orders”An AI gives the same orders a player does.
One unit, one ability. Use Activate Ability With Inputs For Player: Player Me, Entity the unit, Ability Tag, and a Target Entity or Target Location if it needs one. Use it to train, build, mine and cast.
Train is:
- If
Barracksis valid and its Get Production Data Queue has fewer than2entries, - and Get Resource for Minerals is at least
50, - call Activate Ability With Inputs For Player with the Barracks and
SeinARTS.Ability.Produce.Soldier.
Before spending effort on an order, ask Get Ability Availability with the Barracks and the ability tag. It reports the first failing gate, so the AI does not submit an order the player could not. A rejected order is harmless but wasteful, and the AI will repeat it every think.
Many units, one order. Use Issue Broker Order For Player. It sends the units through a broker, the same path as a right-click, and each unit picks its own ability from the Command Context you pass. Attack is:
- If
IdleSoldiershas at leastArmySizeentries andEnemyis valid, - call Issue Broker Order For Player: Player
Me, MembersIdleSoldiers, Command ContextSeinARTS.Command.Context.RightClickplusSeinARTS.Command.Context.Target.Enemy, Target EntityEnemy, Target Location the enemy’s location.
The context says “a right-click on an enemy”, so each Soldier’s Default Commands choose Attack. Pass a Formation Tag, in the node’s advanced pins, to move in formation, and Queue Command to append the order. Gameplay Tags explains context tags.
A node for another player works only where the machine may act for that player. A network host may act for an AI-run player; a standalone game for any player. Nothing is submitted otherwise.
6. Tune and extend
Section titled “6. Tune and extend”- Difficulty. Raise
ThinkEveryfor a slower AI, raiseArmySizefor a more cautious one, and swap Query All Entities for Query Visible Entities For Player for a fair one. - Expansion. More behavior is more branches in the three functions: build orders, a scout, retreat when the army is below a threshold.
- A different brain. The controller is an AI Controller, so it can also run a Behavior Tree, a State Tree or C++. Those do the same two things: read the match, and issue orders.
7. Test
Section titled “7. Test”Set the opponent’s start to AI and play:
- Within a second the Barracks starts training. The queue never holds more than two.
- Soldiers appear and stand still until six are idle.
- Then the six move toward your base together.
- Set
ThinkEveryto90and play again. The first order takes up to three seconds, and the whole game is slower.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause |
|---|---|
| The AI never does anything | The Game Mode’s AI Controller Class is still the plain Sein AI Controller, or it is empty and the log says AI Controller Class is off |
| The slot’s units stand idle | The slot is not set to AI, or the Game Mode that runs is not the one you configured |
| Nothing happens on my machine in a network game | Only the host runs the AI. Check there. |
| An order does nothing | It was rejected. Ask Get Ability Availability, or turn on Log LogSeinSim Verbose and read the gate |
| Train works once, then stops | The queue limit or the cost. Check Get Production Data’s queue length and Get Resource. |
| The AI orders units but they do not obey | The Entity belongs to someone else. The AI may only command its own player’s units. |
| The AI sends units one at a time | It issues Attack from its Soldier loop. Collect the Members into an array and send one order. |
| The AI wins before it should | It uses Query All Entities. Switch to the visible query. |
| The AI sends units that are mid-order | The idle test is wrong. A unit with an active order carries its ability’s Granted Tags under SeinARTS.Ability. Test for that with Has Tag. |
Related
Section titled “Related”- Add Victory, Defeat and an AI: a complete demo AI with mining.
- Match Flow: slots, the Game Mode and who runs what.
- Abilities: the gates every AI order passes.
- Gameplay Tags: command context tags.
- Sein AI Controller and SeinARTS AI Library