Best Way to Dynamically Create Objects with DB info?
Hello!
(Warning: Unity Noob)
So, I'm trying to create a visualization of paper data, as in represent each article that I have with a node (a simple 3D sphere), that by interacting with I can acess the article data. I have setup and SQLite DB and have a class Paper that initiates all it's variables by getting the respective data from the DB.
public class Paper { Database db; public string title, date; int id; public Paper(int id) { this.id = id; this.db = Database.instance; db.StartDataSQLite(); this.title = db.getTitleById(id); this.date = db.getDateById(id); }
Something similar to the above code.
Now I want to attach the data that I get when I create one of these objects to a node, that is a sphere and has all those visualizable features.
I want to open the "game" and have it load the current articles on the database and create a node for each with it's respective data.
My question is specifically what is the best way to do this from here on. I've tried making this MonoBehaviour and attach to a prefab, but then when I create list of prefabs it doesn't initiate Paper, I've tried scriptable objects but I have trouble acessing the data and also initiating Paper, etc. I'm not even sure if how I'm doing this so far is the correct way to do it so any help is welcome. Right now my focus is on making spheres that have the DB info of each paper.
Thank you!
Your answer
![](https://koobas.hobune.stream/wayback/20220613054424im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add Components to some individuals parts of a prefab 1 Answer
Assign ScriptableObject (Inventory DataBase) 0 Answers
Having problem with scoring system., 0 Answers
Prefab list as Database 1 Answer
ScriptableObject Instances Referencing One Set of Prefabs - Changing One SO Changes The same prefab 1 Answer