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 ?

  • 1
    \$\begingroup\$ 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? \$\endgroup\$
    – 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.

  • \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Jul 2 '20 at 16:34
  • \$\begingroup\$ @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. \$\endgroup\$
    – 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.

Distance based loading

Some engines have implemented systems where they know what items are around the player and thereby know what resources are required by those objects. Then they look at where the player is and how far away those objects are and load whatever is closest to them that can fit into memory. These types of systems are usually needed when there is a LOD system which is hitting memory constraints.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.