Search Unity

Any techniques to create custom data structures without code?

Discussion in 'Formats & External Tools' started by joshrmt, Jun 12, 2018.

  1. joshrmt

    joshrmt

    Joined:
    Dec 11, 2012
    Posts:
    2
    I'm looking for an alternative to having to define concrete classes for each and every data structure in the game. I want to be able to add unique stats, effects and calculations without having to edit code and recompile. A lot of people talk about building data-driven games, but Unity makes it very difficult due to poor serialization and inspector woes. I've experimented with several techniques, but none of them have been particularly comfortable.

    Here's an example case:

    Without using code, I want to be able to add potions to the game which grant various effects and impact the player in certain ways. I need to be able to define a 'potion' data type, associate unique properties to them (SipsRemaining / TotalSips), and then allow the player to drink the potion which reduces the SipsRemaining and creates effects accordingly.

    Implementing the drinking effects is simple enough without writing code using flow-based graph logic or various configurable effect components. However, the same cannot be said when it comes to adding and tracking a custom field value. I've searched far and wide for solutions to this, but have come up empty-handed.

    Currently I'm left with writing my own solution, and I can't help but feel that I'm reinventing the wheel. I'm using a combination of ScriptableObjects and custom editors/drawers. First, I define a custom type ScriptableObject: https://image.ibb.co/iD7wxo/GameType.png

    Basically it's just a glorified dictionary. And then I define a 'Template' ScriptableObject using a custom editor, which more or less represents an instance of the type I defined:

    https://image.ibb.co/jE4LOT/Template.png

    Obviously this is only part of the battle, but it does succeed in a basic way to define custom data structures in the editor using ScriptableObjects. I then have an 'Entity' component which references the Template, and allows a transfer of these ScriptableObject properties to an actual GameObject.

    I am hoping someone has already done this and gotten much further than me, because I still have a long road ahead of me to actually be productive with this technique.