I have a group of blend files in a folder and I want to load the objects in all of them when starting my game. I wish to be able to place a new blend file in the folder and have its objects be loaded automatically These objects should be added into a hidden layer so that I can add them in with the addObject actuator later.
I have tried libLoad but that is designed for realtime and therefore doesn’t work with objects.
There is no method to collect all data automatically. You can link in the data from other blend files (manual step). This way you have it available in Blender and BGE.
You can use LibLoad to load game objects or scenes from other blend files (Python code). You can indeed write code that scans through the directory.
I was interested in this too, and I had not messed around LibLoad until you asked this question… so I don’t completely understand what is going on, but this does seem to do what you are looking for.
The way the API reference describes the semantics of LibLoad is confusing. What appears to happen is that with the ‘Scene’ type, LibLoad loads all game objects and their linked data (depending on how you call LibLoad) into the current scene. It also conveniently respects objectsInactive, so if it would be an inactive object (on an inactive layer) in the library, it is also inactive when imported.
So you can do this in a startup script:
from bge import logic
libs = logic.getBlendFileList('//lib/')
for file in libs:
logic.LibLoad('//lib/' + file,'Scene')
Then within this scene later on, assuming ‘Thing’ is on an inactive layer somewhere in the loaded libraries:
I am still kind of confused as to ‘where’ all of the data is imported to. I know objects in all scenes in the imported blend end up in the current scene when LibLoad is called in a single scene game. I do not know if this is the only place they end up though.