Now that the UI for the Skill Tree was set up, I needed to program and develop the hard part.
Getting the Skill Buttons to work when pressed.

- Customizable skill buttons mean skill buttons that can unlock different types of skills – A robust system for creating a skill tree
- Terra Shard UI counter would have to update depending on Terra Shards spent and the players current terra shard count
- Skills can be locked – preventing the player from spending Terra Shards on them
- Terra Shards must be used as the currency to upgrade skills and can be increased by killing enemies in the dungeon
- Prerequisite skills function – certain skills must be purchased before other skills can be unlocked
To set up the Skills System, it requires three scripts:
- SkillSO script – A scriptable object script that handles data about each skill
- SkillSlot script – Handles each skill button (What skills need to be unlocked before it etc.)
- SkillTreeManager script – Communicates between all skill scripts (Handles spending Terra Shards to buy skills etc.)
SkillSO Script
What is a scriptable object in unity? The following is directly from the Unity’s Documentation:

The reason I make the SkillSO script call from ScriptableObject as opposed to MonoBehaviour, is that it is able to save memory when running the project, as all of its values are never changed throughout the game. They are only ever set in the Unity editor before the game is run.
This is the SkillSO script, the CreateAssetMenu attribute allows me to create more ScriptableObjects much easier (“Attributes in C# are metadata markers that can be placed above a class, property, or method declaration to indicate special behaviour” – Unity Documentation). However, the main use of the SkillSO script is to store data about certain skills, hence the public data types for:
- A string called skillName
- An int called maxLevel
- A Sprite called skillIcon (The sprite that will be used for the SkillButton’s Image)


SkillSlot Script
Firstly, for the Skill Button to know when to be unlocked, there is a public list of skills that can be assigned to in the hierarchy which must be acquired before the target skill can be unlocked, In order for the SkillSlot to have access to data about the skill, it needs a reference to the SkillSO, hence public SkillSO skillSO. Then, there are two ints and bools to do with purchasing and being able to purchase a skill.
Then, in the OnValidate() method (This method runs when changes are made to a script’s variables) a check is made to see if the SkillSlot even has a reference to a SkillSO or the skill’s level text. If this is the case, the UpdateUI() method is called which updates the SkillIcon’s sprite to the SkillSO’s sprite. Afterwards, it checks if the skill is unlocked to determine whether to grey out the skill if it is locked or not and updates the CostText text to show how many Terra Shards the player has spent on that skill.
In the TryUpgradeSkill() method, the skill is checked to see if it is unLocked and whether its current level is less than its max level, if this is the case its currentLevel is increased and the OnAbilityPointSpent event notifies listeners (i.e the SkillTreeManager script). However, after the currentLevel is increased, it checks if the new currentLevel is now equal to or greater than that level’s maxlevel. If it is, then the OnSkillMaxed event notifies listeners (i.e the SkillTreeManager script).
The CanUnlockSkill() method checks all SkillSlots in the prerequisiteSkillSlots list to see if all the prerequisite skills are all purchased for that SkillSlot, if they are, then that CanUnlockSkill() method returns true.

SkillTreeManager Script
To start the script, there are references for an array of SkillSlots, the text for TerraShard count, the player gameobject and the PlayerInventory script – which will all be used later in the script.
In the OnEnable() and OnDisable() methods subscribe or unsubscribe from the SkillSlots’s OnAbilityPointSpent() and OnSkillMaxed() events and cause the SkillTreeManager to call the HandleAbilityPointsSpent() method or the HandleSkillMaxed() method with that specific SkillSlot as an input for those methods. Essentially checking if a Terra Shard can be spent on that skill or if that skill is maxed out.
If a Terra Shard can be spent, the UpdateAbilitPoints(int amount) method is called which takes in an int and reduces the player’s currentTerraShards count.
If a skill is maxed out the HandleSkillMaxed(SkillSlot skillSlot) method is called which checks all SkillSlots in the skillSlots[] array, if a skill is locked and the a SkillSlot’s CanUnlockSkill() method returns true, then that SkillSlot’s Skill Button becomes available to be purchased with Terra Shards.
In the Start() method, references to the PlayerInventory script and the amount of available Terra Shards the player has to spend is set. There is also an AddListener() function that is used on each SkillSlot in the SkillSlots array if the button corresponding to that SkillSlot is pressed, hence slot.skillButton.onClick. The CheckAvailablePoints(slot) method is called, which will check if the player has more than one Terra Shard to spend, if this is the case, the SkillSlot’s TryUpgradeSkill() method is called.

Current Prototype
At this point, the player is able to click on a Skill Button and it would unlock it. Shown by the cost text reading ‘1/1’ and the Terra Shard counter decreasing by 1.