Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Skill Tree

Discussion in 'Scripting' started by TritanTechnology, Mar 1, 2017.

  1. TritanTechnology

    TritanTechnology

    Joined:
    Feb 16, 2017
    Posts:
    19
    Hello, everyone! So right now I am working on a RPG title. I have made my skill system by now - the skills work and can be seen in a simple GUI window. I will be really thankful if you share with me some ideas on how can I turn this GUI skill window of mine into a skill tree, where there will be locked and unlocked skills depending on player's level and stats (I have made that too). Thank you!
     
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    without given us any details on how you've done these things... you're going to need (an) attribute(s) on the skill to hold the prerequisite(s), you can then write a function which returns a bool to check if the prereqs are met so the UI can figure out what to display.

    If you want something a bit more specific, you're going to need to provide a lot more detail about what you've done, how etc.
     
  3. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    Also you going to want to implement a design structure called MVC which stands for model-view-controller. The basic idea is the model is your data, the view is how you display that data and the controller talk to each of them. This way your data and your view are separate and never talk to each other so its easy to modify one or both of them without breaking anything, since they are not dependant on each other.

    Your model should have some data classes (maybe scriptable objects) that contain a class of what a skill is something like what @LeftyRighty described. You controller script would then instantiate a big List<> or Array of all the skills. Now then your view would be all the gameObjects in Unity you use to actually draw your Skill Tree. It would scripts to on how to display a List<Skills> it gets passed. Your controller script would then call this function with the data about the skills. This would be a different class that would just hold data that the view needed. The skills name, its Graphics image, some state information if its Activated (already picked), Available, Unavialable. You would fill this in from the data you got from the model. Then send it off to the view. This way you can change all your skills up and preRequirements, whatever, and the view part of your skill tree code won't change. It won't care whats going on over in the model.. its just going to expect the List of skills from the controller.

    And vice versa.. Maybe you view starts off as a big list with drop down arrows for skills that are subskills of other skills. Then later on you decide to change it into a big Skill Tree web like FFX or POE. The model code that contains all the skill information won't change one bit. Just your code on your view scripts with how to display that data.
     
  4. TritanTechnology

    TritanTechnology

    Joined:
    Feb 16, 2017
    Posts:
    19
    Thank you for this comments! Tommorow I can share more about the scripts. I wonder can we leave all the scripts for the skills aside and just give me some advise on how to create the GUI function for the skill tree. Just the placement. And of course ResizeGUIMatrix. Thank you!
     
  5. takatok

    takatok

    Joined:
    Aug 18, 2016
    Posts:
    1,496
    You have a couple of options there. If you wanting a FFX style skill web, i think a static graphic that you create might be easiest. You can come up with a index that tells you exactly where each skill is on that tree, so you can highlight or do other things to those areas. The con of doing it this way is any change in your skill system requires a new graphic.

    You could try some kind of modular graphics. Where each skill has a graphic/icon and you have some kind of method of drawing connecting lines between them. Then you'd just need a set of data points describing where to place all the skills. You could develop a tool that designs the grid and saves the points where you placed all the skills out to a file.
     
  6. p1zzaman

    p1zzaman

    Joined:
    Jan 1, 2017
    Posts:
    64
    Is this skill tree static?

    You can use enums to set up parent child relationships
     
  7. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Even if the skill tree is static at runtime, it's not likely to remain static at development time. Enums strike me as a relatively brittle way to approach this.
     
  8. p1zzaman

    p1zzaman

    Joined:
    Jan 1, 2017
    Posts:
    64
    you can have an enum that implements an interface INode and assign it properties like Node parent, name, etc

    actually I am not familiar with enums in c# but in java you can have it implement an uterface and pass in constructor values during declaration

    but i guess if there are more complex logic like applied effects and such when chosen, I would use something elae
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    You can extend Enums in C#, but it's not the best idea. If you need extra functionality, better to make a full class and hand it around.
     
    p1zzaman likes this.
  10. p1zzaman

    p1zzaman

    Joined:
    Jan 1, 2017
    Posts:
    64
    Agreed, my solution was only for enumeration purposes. Thanks