Slowdown due to game objects that contain references to several prefabs?

Hi! I’m making a strategy/simulation game using NGUI and Unity. The game doesn’t feature any complex 3D graphics or sprite animations, but it does feature a wide array of assets (mostly images and hundreds of text files with data and strings). The game was originally being developed in C++ and the assets were loaded from the files as required. In order to make the porting process to Unity simpler, I created this “container” object that holds references to the TextAssets and the images and then created a “container of containers” object named “GameWorld” that holds an array of containers. Both types of containers are stored as prefabs, which are referenced by a game object that belongs to the first (and only) game scene. The prefabs inside the containers are only instantiated when needed.

Since the game involves the player navigating through a set of nearly 15 screens, I’ve created all of them as prefabs and stored a reference to each one of them in another game object named “SceneOrchestrator” which also belongs to the first game scene. Then I instantiate and destroy the screens as required, I never load a new scene.

The game works well and has no performance issues during gameplay, but it takes a horrendous amount of time to start up when executed as a standalone build (it does load instantly when executed inside Unity’s game editor, though).

I originally thought that having references to lots of prefabs in my “GameWorld” and “SceneOrchestrator” containers was OK provided that I only instanced a handful of them, but my suspicion is that the terrible loading times are due to the fact that Unity is preloading the prefabs references in memory during the scene loading process (the profiler -which freezes until the first scene finishes loading- reveals a total memory usage of 424.7 MB). Is my suspicion correct? If it is, can you recommend a design pattern to deal with my scenario (i.e., the fact that I need to hold references to hundreds of assets in order to be able to instantiate them on demand)?

Many thanks in advance!

–Nacho

You can instantiate Prefab using their name instead of a reference to it. So you only store string.

Cripple, apologies for my late reply. I followed your advice and moved all the prefabs to the Resources folder and instantiated by name and it’s now working great, loading times are nearly zero, so many thanks for that!