Skip to content

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.

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.

  • 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.

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:

  1. Break Sein AI Tick Context. Set Me to Owned Player ID.
  2. Branch on Current Tick % ThinkEvery equal to 0.
  3. On true, call Scan World, Train, then Attack, 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.

Scan World sorts what the AI knows:

  1. Reset Barracks and Enemy, and Clear IdleSoldiers.

  2. Query All Entities with an empty query, which matches everything, and Skip Abstract Entities on. For Each Loop over the result.

  3. Switch on Get Entity Relation for the entity and Me:

    • Friendly with the tag SeinARTS.Unit.Barracks: store it in Barracks.
    • Friendly with SeinARTS.Unit.Soldier: test Has Tag SeinARTS.Ability. A unit with no ability tag has no order, so it is idle. Add it to IdleSoldiers.
    • 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.

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.

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:

  1. If Barracks is valid and its Get Production Data Queue has fewer than 2 entries,
  2. and Get Resource for Minerals is at least 50,
  3. 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:

  1. If IdleSoldiers has at least ArmySize entries and Enemy is valid,
  2. call Issue Broker Order For Player: Player Me, Members IdleSoldiers, Command Context SeinARTS.Command.Context.RightClick plus SeinARTS.Command.Context.Target.Enemy, Target Entity Enemy, 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.

  • Difficulty. Raise ThinkEvery for a slower AI, raise ArmySize for 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.

Set the opponent’s start to AI and play:

  1. Within a second the Barracks starts training. The queue never holds more than two.
  2. Soldiers appear and stand still until six are idle.
  3. Then the six move toward your base together.
  4. Set ThinkEvery to 90 and play again. The first order takes up to three seconds, and the whole game is slower.
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.