1

We have a MonoBehaviour component holding a long list of prefabs (can be 100). Those prefabs are meant to be created/destroyed as needed. The component is singleton getting created on first usage.

The question is related to the memory usage, using a mono behaviour component, I understand this means all the prefabs are being loaded onto the disk when creating the component. I am looking at a way to limit the loading of those rarely used prefabs.

I thought of having them in different scriptable objects so only the lists from used prefabs would get loaded, with the lists of less common prefabs most likely rarely or never loaded.

I am looking at tips on the topic.

fafase
  • 467
  • 3
  • 10
  • 2
    As long as you have any references loaded in a scene, everything is loaded into memory. Do you have a memory problem? Did you use the profiler? Usually it's best not to pre-optimize when you don't have a problem. EDIT: If you do have a problem, you can use addressables or `Resources` to lazy load - this will however introduce some CPU overhead. – Ron Oct 18 '21 at 20:46
  • There is a significant constant memory usage since it can be 100+ of prefabs with textures and components. – fafase Oct 19 '21 at 07:31
  • 1
    https://learn.unity.com/project/getting-started-with-addressables – derHugo Oct 19 '21 at 12:43
  • Another way to reduce memory usage is using object pooling, or sharing the same material between all the objects you spawn to reduce draw calls (not the default one of each prefab). Also, use the profiler to easily spot what consumes too much memory. – Matthew Oct 19 '21 at 16:29
  • did you use the profiler and see a problem? And again, you can use addressables as I mentioned earlier and @derHugo has linked – Ron Oct 19 '21 at 21:02
  • We used the profiler, and could notice a significant spike or memory usage. Using Resources was one solution we tried but then the lag was on loading and creating (sometimes quite noticeable). I'll look into addressables, those were left aside as last time we looked into them, it was adding some issues (would not find an existing item for instance) but it was a while ago maybe it is fully working now. – fafase Oct 20 '21 at 15:32

0 Answers0