How can I load a model into bge in real time from a blend file with python? In other words when the game is running.
By default the BGE loads everything from a scene at scene start. To add more objects to a scene while the game is running you can use bge.logic.LibLoad() to dynamically load all objects from a scene of an external .blend file.
Be aware currently (since 2.78) this is supported:
- loading a single mesh (mesh - not object!)
- loading all objects of a scene
- loading an action
def loadAndMergeScene(): libraryStatus = bge.logic.LibLoad( "//Asset.blend", "Scene") return libraryStatus.libraryName
To unload the merged data call LibFree(). The library name should match the one from loading.
def removeAndUnloadLibrary(libraryName): bge.logic.LibFree(libraryName)