Skip to content

Abilities and Rules

Card abilities and the rules of the game are both ability graphs: assets made of nodes wired together. A card’s graphs go in its Abilities list; the game’s own graphs go in the Game Definition’s Rule Graphs. A keyword can also carry a graph, which a card has for as long as it has the keyword.

Open it by double-clicking an Ability Graph asset, with Open Graph Editor in its inspector, with New Ability Graph in a card’s inspector, or from Tools > TCG Kit > Ability Graph Editor.

  • Right-click or press Space on the canvas for a searchable menu of nodes. Hover an entry to read what it does.
  • Drag from one port to another to wire them. Only ports carrying the same kind of thing can be joined: flow (white), targets (green) or numbers (yellow).
  • Fields that hold an id (a stat, zone, card, card type, keyword or phase) are drop-downs of the ids that exist in your project. A value whose asset no longer exists is marked “(missing)”.
  • Auto Layout arranges the graph left to right in the order it runs. Undo and redo work as everywhere else in Unity.

Every graph starts at a trigger. When an event happens, each graph whose trigger matches is queued; graphs run one at a time, in the order they were triggered. A graph’s flow wires (white) say which step runs next. Data wires (green and yellow) feed targets and numbers into a step; they are worked out when the step runs, so they see everything earlier steps did.

  • A Player Choice pauses the match until the player answers, then the graph carries on. If there are no more options than the minimum, they are taken without asking. A choice or a Random Pick is made once per run, however many steps read it, so “choose a creature: it loses Taunt and gets -2 attack” asks only once.
  • For Each runs its “each” flow once per target, with Loop Item giving the current one, then continues from “done”.
  • Branch follows “true” when its condition is not 0. Compare gives 1 or 0.

Card triggers listen only while the card is in its type’s play zone, so a “start of turn” creature in a hand or deck stays silent. Change this with a trigger’s Active Zone Id: pick a zone, or “(any zone)”.

Example: “When played, deal 2 damage to an enemy creature”

Section titled “Example: “When played, deal 2 damage to an enemy creature””
[On Played] --then--> [Modify Stat: health, amount -2]
^ targets
[Player Choice] <--options-- [Cards In Zone: board, side Opponent]

These four graphs, from the Starter game and the sample, make a complete game loop:

Rule Graph
Draw at turn start On Turn Start (whose: any) -> Draw Cards, players = Event Player
Destroy at 0 health On Stat Changed (health, any card) -> Move Card to graveyard, targets = Filter(health <= 0, zone board) of Event Card
Lose at 0 life On Stat Changed (life, any player) -> Eliminate Players, players = Filter(life <= 0) of All Players
Lose on empty deck On Deck Empty -> Eliminate Players, players = Event Player

For rules that are easier to write in C#, implement IGameRule and wrap it in a GameRuleDefinition asset added to Code Rules. Code rules react to each event immediately, before any graph runs. The built-in DrawRule, DestroyAtZeroRule, LoseAtZeroRule and LoseOnEmptyDeckRule are examples. Rules must keep no state of their own: all state lives in the match.

Every trigger also has Active Zone Id (see above). “Targets” inputs take a list of cards and players; most effects do nothing when nothing is wired into them, and the validator warns about that. Where an input has a matching setting (Amount, Count, Value), the setting is used when nothing is wired in.

Node What it does Wired inputs Settings
On Played A card was played from hand. none Scope
On Enter Zone A card arrived in a zone from somewhere else. none Zone Id, Scope
On Leave Zone A card left a zone for somewhere else. With scope Self this still fires after the card has gone. none Zone Id, Scope
On Turn Start A turn started: yours, an opponent’s, or anyone’s. none Whose
On Turn End A turn ended: yours, an opponent’s, or anyone’s. none Whose
On Phase Start A phase of the turn began. none Phase Id, Whose
On Stat Changed A stat of a card or player changed. Use Event Value and Compare to react to particular amounts. none Stat Id, Scope
On Attack A card declared an attack. none Scope
On Deck Empty A player had to draw from an empty deck. none Whose
Node What it does Wired inputs Settings
Modify Stat Adds an amount to a stat of every target. Damage is a negative amount to a health stat. targets (targets), amount (number) Stat Id, Amount
Set Stat Sets a stat of every target to a value. targets (targets), value (number) Stat Id, Value
Add Modifier Adds a modifier to a stat of every target, optionally only until end of turn. targets (targets), amount (number) Stat Id, Amount, Duration
Move Card Moves every target card to a zone. Destroying, discarding, bouncing and stealing are all moves. targets (targets) To Zone Id, Destination
Draw Cards The wired players, or the controller, draw cards. players (targets), count (number) Count
Create Card Creates new cards in a zone of the wired players, or of the controller. players (targets), count (number) Definition Id, Zone Id, Count
Add Keyword Gives each target card a keyword. targets (targets) Keyword
Remove Keyword Takes a keyword away from each target card. targets (targets) Keyword
Shuffle Zone Shuffles a zone of the wired players, or of the controller. players (targets) Zone Id
Eliminate Players The wired players lose. Everyone wired in loses at the same moment. players (targets) none
End Game Ends the game at once. The first wired player wins; with nothing wired the game is a draw. winner (targets) none
Node What it does Wired inputs Settings
Branch Follows “true” when the wired condition is not 0, otherwise “false”. condition (number); flow outputs: true, false none
For Each Runs the “each” flow once per wired target, with Loop Item giving the current one, then follows “done”. targets (targets); flow outputs: each, done none
Node What it does Wired inputs Settings
Self The card that has this ability. none none
Controller The player controlling this ability. none none
Opponents Every player still in the game other than the controller. none none
All Players Every player still in the game. none none
Event Card The card the triggering event was about, such as the card that moved or was damaged. none none
Event Player The player the triggering event was about, such as the player whose turn started. none none
Loop Item The item the innermost For Each is currently on. none none
Cards In Zone All cards in a zone, for the chosen side of the table. none Zone Id, Side
Filter Keeps the wired targets that pass every test that is filled in. Tests about zones, keywords and card types only ever pass for cards. targets (targets), value (number) Zone Id, Keyword, Card Type Id, Side, Exclude Source, Stat Id, Comparison, Value
Player Choice Asks the controller to pick from the wired options. When there are no more options than the minimum, they are all taken without asking. options (targets) Min, Max
Random Pick Picks some of the wired targets at random, without repeats. targets (targets), count (number) Count
Players Of The owners or controllers of the wired cards, each listed once. targets (targets) Use Owner
Node What it does Wired inputs Settings
Constant A fixed number. none Value
Stat Of A stat of the first wired target, or 0 when there is none. target (targets) Stat Id
Count Of How many targets are wired in. targets (targets) none
Math Op Adds, subtracts, multiplies, divides, or takes the smaller or larger of two numbers. a (number), b (number) Operation, A, B
Compare 1 when the comparison holds, otherwise 0. a (number), b (number) Comparison, A, B
Event Value A number from the stat change that triggered the graph. 0 for other events. none Kind

To add your own nodes, see Extending the Kit.