# How to load 3D modells when they are necessary

I'm working on a 3D game engine, currently I load ALL of my 3D modells into the memory when my game starts, but obviusly there will be hundreds of 3D modells, so somehow I should unload them when they are out of the range, and load them again when the player is going to go near them.

What is the best way to do this ?

• We can't tell you the best way to do this, because it will depend on how your game is architectured. What have you tried so far? – Vaillancourt Jul 1 '20 at 17:24

It also depends on the engine you're using, but for example:

In Unreal Engine 4, you use something called "Level Streaming" where you open a level that you want to remain persistent (meaning, a level that is always loaded) and add sub-levels to it that load when certain events are triggered. These sub-levels work in a similar way to layers in say, Photoshop. You can hold any amount of 3D models, animations, post processing, etc on each "layer" (sub-level).

I'm sure other engines have similar functionality but possibly under a different name.

• Since this question is tagged java and opengl, I think it's safe to assume this user is not building on an existing engine, but implementing this feature in their own original codebase. – DMGregory Jul 2 '20 at 16:34
• @DMGregory my mistake. ON/IN makes a big difference and I missed that. In any case, it's hard to say how this should be handled. But maybe my comment could still provide some ideas. – Zii Jul 2 '20 at 17:25

There are many strategies to do this, I'll just list the most common the ways people have done them in the past and you can then use this as a jumping off point for more research.

## Scene files

Define a scene (or level) file which specifies where and what is inside the level, you can then use this list to load data as it's needed and unload when you switch to a different scene. Sometimes you want multiple scenes in the world and could potentially have to maintain multiple lists of assets, it all really depends on the requirements of the game your trying to build.