Object preloading (speed optimization)

Hello,
I have lots of objects for my game to load, but most of the time it depends on the user which objects are used in the game. Usually some unjects are not used. When I need two of the same objects, for example a table, I load every table individually with assetsManager.loadModel() …
I’am thinking of a solution: Loading all objects at the whole beginning of the game, and store them in a list or something. When I need an object to add it to a node, then I get it from the list. When I need more of the same Spatials, I just clone them from the list.
I haven’t tested this yet. My question is: If I clone a Spatial (with java.lang.Object.clone()), and I change anything of the cloned object, does that affect the original spatial?
I also can use renderManager.preloadScene(), but what’s the best?

If you have managed to load object once, you don’t need to worry - it is already cached in asset manager and will be a lot faster next time. It still needs to be cloned, so if you are talking about hundreds/thousands instances, you may want to look into other solutions (batching, instancing), but for just loading it few times, trust asset manager. You don’t need manual list.

But yes, you need to preload it. I had mixed success with preloading in non-rendering thread, I was experiencing considerable slowdowns in any case, but other people reported it working without issues.

1 Like