Initializing textures/models/sounds

Hey, a problem I am running into is, when adding objects to a scene, it lags because it has to load textures from the HDD. Is there a way to load all the models, textures and sounds into RAM beforehand other than packing the textures into the blend?
This kind of defeats the purpose of LOD and texture streaming, but the textures and models in my game are usually 4 vertices (2 tris) and maximum 20KiB in size.

I searched Google and the forum for this, but found no results (might be using the wrong terms).
Thanks.

Adding objects should not cause lag, they are already in ram.

When adding objects from another layer it does lag while loading it… It might be the ram moving textures to the graphics ram, or the gpu processing the alpha channels (no idea). Once the texture has been loaded, it doesn’t lag when adding another “instance” of the object, which is why I need a way to load all the objects in a .blend once before going into the game.

Sorry to bump, but I think I figured out how I need to do this, but need help coding it.

The idea is to load every object in a scene prior to going into the actual game scene, so I’d need to do something like load one of every object from each scene. I have this so far:


import bge
from bge import logic
scene = [scene for scene in logic.getSceneList()]
objects = [objects for objects in scene.objects]
print(scene)
print(objects)

logic.getSceneList() doesn’t allow to show scenes that aren’t loaded, so is there another way to get all the scene names?
Also, how do I represent scene as a scene name from a list, instead of a list?

Thanks

You cannot get a list of inactive scenes with the current API unfortunately, and you’ll be looking for inactive objects, which can be found using:
scene.objectsInactive

You also cannot add objects from one scene into another.

I really am mystified about this, as I have never had lag adding objects in the past couple years I’ve used BGE, regardless of object complexity. If you can share a blend, I’d like to take a look.
I think it more likely that a script is doing something the first time it is run, and it is only run the first time the object is added.

I’d share the .blend, but then I’d have to pack all the textures and sort through all my project files so I don’t have to upload over 500MiB, which isn’t a great idea for me (slow internet). I can explain the setup:
When an enemy dies, or is shot, it adds “blood” objects using rays at the ray.hitPosition and then orients them to the ray’s normal from an empty. When shot it only adds one, however when the enemy dies, it adds many empties that spawn blood, parented to another empty that rotates at random (up to 50… needs a bit of optimization… but it’s still not that many faces considering it’s just planes).

I think it would be true that the only happens the first time it runs, however once restarting the game, it doesn’t lag on first time adding again. Does Blender keep the objects/rays/near/collision/scripts/random/etc. in a cache after the game is played?

EDIT: After packing textures into a separate .blend, it still lagged on first instance.

[SOLVED]:
2nd EDIT: After some testing, I found that it was a spot lamp that had shadow enabled… I can’t believe that it caused that much of a problem when new objects were added, even though they had shadow disabled in their material options. I feel lake an idiot :stuck_out_tongue:

Thanks for the help anyway :slight_smile:

Out of interest, were you adding the spot lamp, or was it already in the scene and you were adding other things?