Separating UI from data
I'm curious to hear different approaches on how to separate UI from data, as I'm in the planning phases of a new game that requires a database to store various items. I'll need to access various properties of these items during gameplay, as well as display them in several different menus. I want to approach optimization as a design consideration rather than an afterthought, so I thought it would be best to separate UI elements from the data.
For example, I have a Weapon class that stores values for its name, damage, durability, and health, as well as functions for inflicting damage, reducing health, and breaking. Rather than also storing their UI icons, I have a separate class that is responsible for rendering Weapon icons in the various screens. So when the menu is loaded, it initializes by checking to see what the player has in their inventory, cross-referencing a collection of icons, then populating the menu.
Does that make sense?
I would love to hear some input on this approach. Is there a better way to handle this? Specifically how could I go about doing this? Would I store ID keys in the data classes, then use those to reference the media externally?
Thanks!
P.S. I plan to be using ScriptableObjects for the individual items, which I could then pass into the UI renderer to display the appropriate information.
Answer by Cuttlas-U · Mar 01, 2018 at 09:13 AM
hey; did u try unity "Scriptable Objects" ?
its so optimized and very fast;
u can use it to hold as much data as u need;
Hey!
Yeah, I plan to use them as my means of storing instances of those items, but wouldn't it still be better to separate UI from data?
i cant get what u say ; can u show me some screen shots ?
Your answer
![](https://koobas.hobune.stream/wayback/20220612153619im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
chests and looting with ui 1 Answer
How do I stop my main menu from closing before the player is done interacting with it? 0 Answers
Best way of doing inventory in UI 0 Answers
Inserting game items in online database table and connect that table with the users table 0 Answers
How to handle inventory in 2d game, via xml, no game objects (inheritance? interface?) 0 Answers