[Help] On demand asset reference

Hi,

I’m extensively using Scriptable Objects in my project. I have an Scriptable Object that have references to all characters Prefabs in the game. If any asset in the scene has reference to this Scritpable Object, then Unity load all prefabs in memory, and recursively it loads animations, sprites, etc. and uses a lot of memory.
How can I have an asset that can make reference to many prefabs without loading them in memory, or loading then just when I need?

Thanks!

You can’t late-load prefabs, because they don’t exist by the time the game is compiled. You can late-load assets, such as sprites, textures, audio and video. Unity - Manual: Loading Resources at Runtime

You probably shouldn’t worry about small things like animations. They’re just a few numbers.

1 Like

Thanks! But I didn’t understand what you mean by “You can’t late-load prefabs”. I can put prefabs in resources folder and load them by path. I don’t like using Resource folder, but I think it’s the easiest way.

The problem with animation is that they have reference to the sprites.

I mean that prefabs are only a convenience for developers. By the time your project is compiled, they become a list of resources, and code to construct the object. Prefabs don’t exist in the compiled code, so there’s nothing to late-load. But it looks like AssetBundle might support prefabs anyway (probably as a list of assets). So that’s worth looking into. It might help with the animations, if the animations are part of the bundle.

Maybe a more experienced Unity developer than me can step in here. This has to be a solved problem (or it’s a huge omission by the Unity team).

1 Like