Sub topic 9
Skill Trees and Skill Points
A skill tree lets the player decide how their character grows. Levels (covered earlier) say how much power a player has earned. A skill tree says how the player spends it. This chapter covers the working model of a tree, how skill points act as a budget, the code that enforces the rules, and the errors that show up most often.
This chapter assumes you have read the earlier chapters on XP and levels and on unlock conditions. It also assumes you can read short Python samples and are comfortable with sums and simple graphs.
What a skill tree is
A skill tree is a set of abilities (nodes) connected by prerequisites (edges). A player earns skill points, usually from leveling up, and spends them to learn nodes. A node becomes available only when the player owns every prerequisite and can pay its cost.
Each node has three properties:
- A cost, paid in skill points.
- A list of prerequisites, which are other nodes the player must already own.
- An effect, such as a new attack, a passive bonus, or a new unlock.
A skill tree is an unlock gate (see the previous chapter) with one change. A level gate opens for everyone who reaches it. A skill gate opens only for players who chose to spend points on it.
Skill points are a budget
The core of a skill tree is a resource constraint. If every player could learn every node, there would be no choices and no tree. The designer controls two numbers:
- Points earned by the level cap, or by other sources such as quests.
- Total cost of all nodes in the tree.
The ratio between them decides how the tree feels.
| Points earned vs. total cost | Effect on players |
|---|---|
| Much lower (for example 30%) | Strong specialization. Every point is a hard decision. Builds differ a lot. |
| About half | Players fill one or two branches and sample others. |
| Equal or higher | The tree is a checklist. Every player ends with the same build. |
Many games set the budget below total cost during the main game and then add points at endgame. That way the early choices matter, and completionists still have a goal.
A worked example
The sample tree below has four skills. slash is the root. whirlwind and berserk both require it. execute requires both.
The total cost is 1 + 2 + 2 + 3 = 8 points. Suppose the player earns 6 points by the cap. They can learn slash, whirlwind, and berserk (5 points), but then execute costs 3 and they have only 1 left. They can also skip one middle skill, but execute needs both. So in this tree execute is unreachable at a 6-point budget. That is a design bug, not a choice. We return to it in the errors section.
Implementing the rules
Store the tree as data: a dictionary from skill name to cost and prerequisites. One function then answers "can this player learn this skill right now?"
SKILLS = {
"slash": {"cost": 1, "requires": []},
"whirlwind": {"cost": 2, "requires": ["slash"]},
"berserk": {"cost": 2, "requires": ["slash"]},
"execute": {"cost": 3, "requires": ["whirlwind", "berserk"]},
}
def can_learn(skill, learned, points):
node = SKILLS[skill]
return (
skill not in learned
and points >= node["cost"]
and all(r in learned for r in node["requires"])
)
def respec(learned):
"""Forget all skills and return the refunded points."""
refund = sum(SKILLS[s]["cost"] for s in learned)
return set(), refund
learned = {"slash"}
print(can_learn("whirlwind", learned, 2))
print(can_learn("execute", learned, 5))
print(respec({"slash", "whirlwind"}))This prints True, False, and (set(), 3).
The second call returns False even though the player has 5 points, because execute needs whirlwind and berserk and neither is learned. The check has three separate conditions, and each blocks learning on its own:
- The skill must not already be learned. Without this check, a player could pay twice for the same node.
- The player must have enough points.
- Every prerequisite must be owned.
respec refunds the sum of the costs of learned skills. Because the refund is computed from the tree data instead of stored separately, it stays correct if a skill's cost is later patched, as long as you decide whether old players get the old or new price.
Validating the tree itself
Data can be wrong. Two mistakes break a tree completely: a prerequisite that names a skill that does not exist, and a cycle, where A requires B and B requires A. Nothing in a cycle can ever be learned. Check both when the game loads.
def validate(skills):
for name, node in skills.items():
for req in node["requires"]:
if req not in skills:
raise ValueError(f"{name} requires unknown skill {req}")
visiting, done = set(), set()
def visit(name):
if name in done:
return
if name in visiting:
raise ValueError(f"cycle at {name}")
visiting.add(name)
for req in skills[name]["requires"]:
visit(req)
visiting.remove(name)
done.add(name)
for name in skills:
visit(name)
validate({"a": {"cost": 1, "requires": []}, "b": {"cost": 1, "requires": ["a"]}})
print("valid tree passed")
try:
validate({"a": {"cost": 1, "requires": ["b"]}, "b": {"cost": 1, "requires": ["a"]}})
except ValueError as error:
print(error)The function walks each skill's prerequisites depth first. If it meets a skill that is still being visited, it has found a cycle. It prints valid tree passed and then cycle at a.
Run validate in a test or at startup. A bad data file then fails loudly during development and never reaches a player.
Common errors
Unreachable skills. The execute example above shows this. For every skill, the cheapest path to it (its own cost plus all ancestors) must fit within the points a player can have at the intended level. You can compute this per skill and flag any that exceed the budget.
Dominant nodes. If one skill is better than all alternatives at the same cost, every player takes it. The choice disappears. Playtest data usually shows this as a node with a pick rate near 100%.
Dead nodes. The opposite problem: a node almost nobody takes, so its points are wasted design effort. A pick rate near 0% is the signal.
Free early decisions with expensive consequences. If a player's first points commit them to a branch they cannot leave, and they cannot see the later nodes, they may feel punished for choices they could not evaluate. Show the whole tree from the start, even locked nodes.
Changing costs after launch. If you patch a cost, players who already spent points have builds that no longer add up. Either refund and let them re-spend, or grandfather the old cost. Decide this before the first patch.
Trade-offs to decide up front
- Cost shape. Flat costs (every node costs 1) are easy to explain. Rising costs (deeper nodes cost more) make late skills feel valuable and slow down fully built characters.
- Prerequisite count. One prerequisite makes a path. Several prerequisites make a convergence point like
execute. Convergence rewards planning but raises the chance of unreachable nodes. - Refundability. Free respecs encourage experimentation. Costly respecs make choices feel weighty. The later chapter on respecs covers this in more detail.
Exercise
A tree has skills A (cost 2, no prerequisites), B (cost 3, requires A), and C (cost 4, requires A and B). The player earns 8 points by the level cap. Can a player learn C? If not, give the smallest change to the tree that makes C reachable without changing any other skill's cost.
Show answer
Learning C requires A, B, and C itself, so the total is 2 + 3 + 4 = 9 points. The player has 8, so C is unreachable. The smallest change that keeps the other costs fixed is to lower C's cost to 3 (total 8), or to remove the requirement on B (total 2 + 4 = 6). A third option is to raise the budget to 9 points.
Exercise
In can_learn, which of the three conditions would you remove to let players learn a skill twice, and why would that be a bug in most games?
Show answer
Remove skill not in learned. The player would then pay points again for a skill they already own, wasting points and possibly stacking the effect twice.