Working on a game which will have hundreds (if not thousands) of levels. Levels are created by the client and exported as an individual json files. Files are small, around 500 bytes each.
I’d like a way to reference them all in a single scriptable object file as a simple TextAssets list or array. I never worked with so many files before so I don’t know if that will impact game starting time on low-end mobile phones? If all those files are referenced in the SO as a single list, will Unity try to load/check them all at once on game load?
If you load something like an SO or prefab, Unity loads EVERYTHING necessary to stand it up in memory.
I’ll guess that it won’t be a major issue. A thousand levels would be half a megabyte.
If it turns out to be a chokepoint, you could make some kind of simple index that lets you rapidly retrieve a single one without loading all the rest of them.
If I were you the first version would have a directory where all these JSON files land, then just use Resources.LoadAll<TextAsset>("MyLevelDirectory/") to pull them all in and iterate them to find what you want.
EDIT: I would also create a system with an actual API to get these levels.
This way your entire game would ONLY use that API to get levels, such that in the future if you have to revamp how they are stored, nothing at all in your game changes.
eg, don’t go spamming MyLevels.LevelList[27].EnemyCount everywhere in your game code.
Instead have an API like
var level = MyLevelRepository.GetLevel( 27);
var enemyCount = level.GetEnemyCount();
Yes, I wasn’t afraid of the memory impact but rather the file system pulling thousands of small files at once on low end devices…
That was my idea too, even don’t load them all at any point, just naming them according to level number and using single Resources.Load<TextAsset>("MyLevelDirectory/level 0005") for example to load single level when needed.