Looking for help to make a multi-type array

So in my game I want to make a skill tree, and I want to try to keep my skills organized in an array which divides them into the sections for the different characters. Then I want to reuse the same gameObjects, but change their data (Image, position, cost) to match the skill I assign. What I am having trouble on is producing an array that works like this. I’ve looked up answers for this and tried creating a class that works like this, but I can’t even get a list going –https://answers.unity.com/questions/698312/store-multiple-types-of-data-in-an-array.html--. Am I going at this the right way, or should I organize things differently?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillTreeListClass
{
    public string myMainClass;
    public string mySubClass;
    public string mySkillName;
    public GameObject mySkill;
    public Image myImage;
    public Transform myTransform;
    public GameObject myRequirement;
    public int myCharacterPointsCost;
    public int mySkillPointsCost;

}
//What I want --> type[,,] SkillTreeSkills = new type[2, -, -, -, -, -] { };//Main Character class (string), Sub Character Class (string), skill name (string), GameObject(of the actual skill), Image(of the skill), transform(transform or x & y (float)), gameobject evolved from(or skill needeed to unlock this skill), skill point cost (int)

//What I tried so far...
    private List<SkillTreeListClass> list = new List<SkillTreeListClass>() { "MainClass1" };

Thanks

Rather than GameObjects, something like a Skill Tree might be better done with ScriptableObjects.

Whatever your base skill object is would have enough in it to relate it to other skills (eg, “I require this skill” and “I modify this skill”), and then you can derive from that base skill object for custom skills, and even have multiple instances of each custom skill.

Check out some tutorials on using ScriptableObjects. The key is you will NEVER be able to stand all the features up in one giant sneeze of code. Instead, start trying some things, grow and iterate, see where the pain is, refactor, grow some more, etc.

ALSO: be sure to completely divorce the notion of what the skill is from how it is presented. The LAST thing you want to do is suddenly realize you want to make all your skill tree icons become 3D objects instead of 2D sprites and then have to go and touch everything. Keep the underlying data separate from presentation onscreen.

2 Likes

Awesome thanks, just what I needed.