Data-driven alternative to hardcoding stat curves

I’m working on character balance for my game, and I’d like to have unique stat increases on a per-level, per-character basis, such that Bob The Warrior might get HP and strength up at level 2, strength up at level 3, and Jimmy the Wizard gets an int increase for both levels.

I’ve been prototyping this by creating a list of bonuses by level on each character’s gameobject, such that you can locate anyone’s stat increases by querying someCharacter.statIncreases[someCharacter.level]. This works, but it’s super-duper clunky; is there any straightforward way I can get Unity talking to spreadsheets/CSVs and manage all of my advancement stuff with a data-driven workflow, or would getting spreadsheets importing cleanly be labor-intensive enough that I’m better off sticking with hand-curated lists?

I’d recommend using JSON to import data into Unity; it has built-in support for that:

If you like CSV’s, you can create your data in Excel, export to CSV, then use a converter, like this site:

to automatically convert the CSV file to a JSON file which you can import.

You could also manually parse a CSV using string.Split or use the builtin TextParser from Visual Basic but I wouldn’t really recommend either of those… JSON is better in the long run for getting things into and out of Unity.

Also if you want to be nifty, you could look into using AnimationCurve as your stat growth curves. not what they were orginally intended for but it has a great UI and you can easily use it for your character’s stat growth. just treat the x axis as the level and the y axis as the stat.

then in code instead of calling “someCharacter.statIncreases[someCharacter.level]” you’d call “someCharacter.statCurves.HealthCurve.Evaluate((float)someCharacter.level)”. where statCurves is just a serializable class holding public AnimationCurve fields.

1 Like

Oh hey, thank you for the links! I’m consistently surprised at how nicely JSON works with Unity… and yea, the evils (well, not evils, but finickiness) was what was making me leery of working with manual string parsing.

Also, holy cow, that is a great idea regarding the animation curves; I don’t think I’ve ever used them for their intended purpose since we do all of our animation everything outside of the engine, but now that you’ve pointed me at them, this is a great UI for all kinds of data niceties.

1 Like