Hello,
I have three hierarchy levels.
Is there a “best practice” to load/save game data from/into file and populate these data structure in the UI lists? Each hierarchy is on a separate canvas.
e.g.
Categories
—- Sub1Categories
———Sub2Categories
I.
Store these via Scriptable objects and save them with Json and load and populate ui
II.
Store them some ways into separate dictionaries.
Without any scriptable objects.
III.
MySQL in Unity, without remote server?
What do you think, which is more managable if you want to add items to each hierarchy level?
the question is very broad and you will need to add a lot of context to be able to get a good answer.
What does your game use to persist the save data ?
Do you reference UnityEngine.Objects in your game data ?
Why is the UI structure relevant here ? isn’t getting the data the most important step ?
I am gonna go ahead and just assume that what you ask for is how to store data that has a “tree” structure to it.
The easiest way imo is to have something like :
public class NodeRef
{
public int nodeIndex;
public string nodeData;
public int[] subNodesIndicies;
}
public class GameSaveData
{
public NodeRef[] allNodes;
}
with this kinda structure you avoid serializing deep branches and you simply save all nodes in a flat array and then just refer to the sub nodes by their index.
So in your example the categories would be saved as JSON you would get something like :
{
allNodes :
[
{ nodeIndex : 0 , nodeData : “Categories” , subNodesIndicies : [1] },
{ nodeIndex : 1 , nodeData : “Sub1Categories” , subNodesIndicies : [2] },
{ nodeIndex : 2 , nodeData : “Sub2Categories” , subNodesIndicies : [ ] }
]
}
Hello,
thanks, I dig into scriptable objects it is really helpful, and are great managable from editor.