# How to Store Design Data in Unity including Formulas?

My team is switching to Unity 3D for an upcoming project. I'm tasked with converting our game data system into Unity.

Our existing games use spreadsheet documents (Google Docs) for designers to set values and formulas. This is then exported into an XML doc (and obfuscated) and read in by our game client. I'm trying to figure out a way to accomplish this same thing but solely through Unity. Storing, exposing, and reading data through Unity is pretty straightforward but I'm not sure on supporting formulas.

I realize I can write a custom parser and interpreter which can handle formulas but I'm wondering if there is already a way to do this in Unity.

For example, let's say I have a unit with various stats: Level, Max HP, HP, Damage, Victory Reward, etc. That unit may receive a reward after combat which is based on its Level and remaining HP. A designer would be able to enter into the Victory Reward field either a flat value, like 3, or a formula such as "Floor({Level} * ({HP} / {Max HP}))", something like that.

My question is basically, is there an existing solution for handling data with formulas in Unity, via a downloadable asset or something in Unity itself, or is there a simple framework or technology which already can do something like this which can be easily integrated (example: some kind of JSON extension which supports self-referencing other values and basic mathematical/logical operations)?

• Store formulas or load specific spreadsheet formulas format? – wondra Apr 4 '17 at 16:39
• The formula should be stored but then interpreted when the client starts up. – Nick Gotch Apr 4 '17 at 16:43
• Do you need to store those formulas in Unity? Or would it be acceptable to process the formulas in your Google Docs spreadsheet to produce the outputs you need in a particular range of cells, export the sheet as xml or csv, and import the result as a TextAsset? That way you're not spending development effort duplicating functionality that Google Docs already handles for you, and you don't need to worry about bugs where a formula is interpreted differently by the two tools. – DMGregory Apr 4 '17 at 16:45
• That's the thing, I'd really like to have it all in Unity and get away from importing the spreadsheet from Google Docs. Over the years we've found issues with this (the spreadsheet is independent of code branches/streams and caused issues, etc). If it comes to it I can go with another import system but I'd like to just have it all in Unity itself. – Nick Gotch Apr 4 '17 at 16:47

The canonical way in Unity to create "data-assets" is by implementing ScriptableObject's. This allows you to create a custom type of asset which you can then create and maintain in the Unity editor (optionally using some custom editor controls which you also need to program). This would allow you to create aUnitType asset with all the fields mentioned in the question and then assign the UnitTypes to units in the scene.