- Home /
Loading subset of information from a file
What is the best/most appropriate way to load information that will be referred to relatively infrequently? For example, a file with the text for hundreds of 'event pop-ups' (like Crusader Kings II/III, Stellaris) or lists of names being used for random characters.
Loading it all at game start is an obvious solution, involving reading it from a file into objects and holding it for use. This is useful in that my event/character manager objects can reference the information easily. However, I know this can also be quite expensive in terms of loading times and involve loading information that may not be used during the session (potentially hundreds of objects sitting and waiting).
Loading at need would only bring in the information as needed, but would need me to iterate over a file to find the exact ID number and pull the information in specifically. Iterating over a file to find a specific string could be quite expensive as well, and would be done fairly frequently.
Is there another way I could look to do it?
Answer by darnoldi · Oct 21, 2021 at 09:28 AM
Hi,
You are correct that iterating through a flat-file every time you need to find one entry is expensive when there are hundreds of entries.
What you have here is the perfect use case for a local database. Something like SQLlite would be appropriate. There are many great, inexpensive assets on the store to make implementing it pretty easy across multiple platforms.
HTH
Your answer
![](https://koobas.hobune.stream/wayback/20220613044427im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to make Advanced save and Load Files? 1 Answer
Is it bad to have this many materials? 2 Answers