- Home /
Random Scriptable Object from Database?
I am making a game that I want to use a lot of Scriptable Objects in, to that end I've made a bunch of Editor tools to create what are essentially big data containers, all of the same type, all inheriting Scriptable Object; thinking these would be an ideal solution.
.
My idea focuses around the player having to meet "Requirements" to be given different options on how they react. A container looks something like this: public class Scenario : ScriptableObject {
public string description;
public List<Answer> possibleAnswers = new List<Answer>();
public Requirements requirements; // To receive the question.
}
public class Answer : ScriptableObject {
public string answer;
public Requirements requirements; // To be presented the answer.
public void DoSomething(PlayerCharacter pc){
}
}
The requirements object looks something like:
public class Requirements : ScriptableObject {
public int strength = 5;
public int intellect = 0;
public int charisma = 0;
...
public bool Compare(PlayerCharacter pc) {
if (pc.Passes()){
return true;
} else {
return false;
}
}
}
So what I want to do is basically search for a Scenario based on what the player character stats are; but I want a really large database of the Scenario objects. Most of the ways I've thought of involve searching a small section of the Resources folder and then hold any that the player passes the requirements of. But I have no idea how to go about searching through with that many objects.
I don't want to use Resources.LoadAll() because it isn't recommended and apparently slows it down exponentially, I plan to have a large number of SO's so anything such as that isn't an option. I don't really fancy linking 10k Scriptable Objects up to a Gameobject because that seems like a bad idea on the face of it but maybe it's not?
One solution I have is to use folders and split Scenarios into folders containing x number of objects then choose a random folder (or the next folder) to search through each frame but this seems clunky as well. Any good solutions or tried practices I'm totally missing?
10k SO already sounds like a bad idea, but if you have to ... You can store your SO database in a static variable so you only need to load them once. Search/check through 10k elements by 3 int variables should be fast enough (1-2ms). You can also try Addressable instead of Resources but it's async.
Your answer
Follow this Question
Related Questions
problem updating info to data base 0 Answers
How can I store a CSV file online on a server and use the CSV to load data into my Unity game? 1 Answer
How to upgrade from free to paid version and maintain established player prefrence data? 0 Answers
Files in Persistent Data path after building the game 1 Answer