Large Technology (Skill/Talent) Tree / Graph

I have a number of years in web development and know a little bit of C++, however I am still learning my way around unity and C#!

How should I be getting started implementing a technology tree for a turn-based strategy game in unity? (i.e., master of orion, civilization, old WoW skill trees, etc.) I have built a prototype of my tree using PHP/MySQL for web, but I am still unsure of how and where I should be storing this kind of data in unity.

The tree will have around 200 nodes with over 500 individual technologies throughout, I dont know if this might be a bit large for efficiently using XML / databases? I would like to eventually develop this game to be multiplayer, and I will probably be adjusting and balancing the tech tree constantly once I start testing the game. Obviously I dont want anyone being able to alter the something like XML files and modify their game client to have technology with different stats either.

What would be an optimal and secure means of implementing something like this? Any suggested starting points or recommended tutorials would be of great help! Most of the videos I have come across so far are not very clear or dont seem practical for a large tree.

If you used XML you’d still have to load it into memory and parse it.

You could go with a ScriptableObject as the skill tree, which then has a class for each node.

Or you could just not have it serialized at all, and just have a factory that builds the skill tree.

In the end though, you’re going to have to have some skill tree/node collection to actually work with the data. So this isn’t a matter of “optimal”, it’s a matter of how you want to store the actual data.

It’s more about what you need to do with it. Such as if you want to allow the skill tree to grow via updates. Or if the skill tree is too complex to have fully loaded into memory. What sort of structure is the tree (simple binary or ternary tree, more complex trees, hashable trees for quick lookup, etc)?

What are your requirements?

With out knowing your requirements, a skill tree is really just a plain old ‘tree structure’.

Hi lordofduct, I’ll try to explain my requirements a bit more.

The tree would begin with a handful of available nodes. Upon researching one or more of these, more nodes would become available as one progresses down the tree. Some nodes would have multiple prerequisites, while others may only have one. Some nodes will have no children and thus be ‘dead end’ technologies.

I suppose this would be considered more of a directed acyclic graph than a ‘tree’. Also I do plan on growing or rearranging the tree through updates, especially during development. That means I plan on altering all of the technologies within the tree for balance and testing too.

In game, researching new technologies will allow the following:

  • unlocking new buildings, or special production focuses

  • unlocking new ship classes, weapons, materials, systems, etc

  • giving passive bonuses to player(s)

So it’s a basic tree.

You need support for modifying the tree post release.

You need an easy way to modify the tree.

XML/json/etc - this option satisfies those needs nicely. If distributed in a assetbundle (post release) there is risk of someone injecting their own modification into the assetbundle if it’s stored locally on their machine. Minimal risk of this though, and big whoop unless you have multiplayer support.

Nice bonus is that it’s relatively easily human readable for while you’re editing.

ScriptableObject - this option also works well. But unlike xml/json/etc, when serialized by unity and distributed in assetbundles, the format is a bit more cryptic to figure out.

Downside isn’t as nicely human readable. Though you can create a custom editor to do which can be nice… but also time consuming.

Self serialized class structure - sort of like ScriptableObject option, but you can control the serialization more directly, and can use something super impossible to read once serialized.

Furthermore you can create a tool outside of unity that helps you edit trees, export to the serialized format, and then import at runtime in your game.

Furthermore, this custom serialization means that it can be saved to disk if modified in game. Helpful for saving the gamestate of a players game.

This all deals with just your serialization/editing needs, since you can’t really use hard-coded if you plan on modifying in the future. (AssetBundles don’t support new scripts so well, meaning you’d have to actually patch the game to get new code into it)

As for the tree structure in code. You’ll need to deserialize/parse this information from above. Since it’s really not that much data, you can just load it into memory no problem.

But you’ll need to create whatever tree structure out of a class. It’s similar to a LinkedList, just with multiple ‘next’ nodes. Shouldn’t be to hard to set up.

Thanks for your suggestions, I think I will probably stay away from XML/json then.

Would ScriptableObjects and self serialized class structures would be individual C# scripts? Not sure where these are supposed to go.

I am not sure what makes creating an outside tool more appealing for self serialized class as opposed to ScriptableObject, but I have been thinking about doing this considering the amount of data I have as it would be a lot more organized.

I’m trying to find some good tutorials or examples, if you point me in the right direction it would be greatly appreciated.

no idea about tutorials or examples, especially in the scope of unity. I don’t really use them very much myself, I just depend on my computer science knowledge and background (never was a fan of “tutorials”).

My point about an outside tool was that creating a GUI for drawing/modifying the tree might be easier in a GUI framework designed more for that sort of thing. Since any custom serialization would be easy to implement, as serialization isn’t really unity dependent when you don’t use the unity serialization system (which you pretty much have to if you plan to have save states).

Scripts go wherever you want in your Assets folder. I usually create a folder called ‘Code’, and organize in folders below that.