How can i append an entire collection from another blind file in game runtime?
In UPBGE 0.3+ we use a BPY operator to append / import a blend asset; such as an object or collection, and then convert it from a BPY object to an BGE KX_GameObject.
import bge, bpy def main(self): filepath = "D:\\Blender\\Projects\\untitled.blend" bpy.ops.wm.append(directory=filepath+"/Object/", filepath="untitled.blend", filename="Suzanne") self.owner.scene.convertBlenderObject(bpy.data.objects["Suzanne"]) print(self.owner.scene.objects["Suzanne"])
A few other facts to know:
- You can mass convert BPY objects to BGE objects via a list or collection group.
- Make sure to use the appropriate count and type of slashes depending on your operating system.
Ok. But i was trying to just get the entire collection.
In this script example, you can import a collection from an external blend file, then mass convert all child objects from that collection into BGE objects.
import bge, bpy def main(self): COLLECTION_NAME = "My_Assets" BLEND_PATH = "D:\\Blender\\Projects\\untitled.blend" ASNC_LOADING = True bpy.ops.wm.append(filename=str(COLLECTION_NAME), directory=str(BLEND_PATH)+"\\Collection\\") self.owner.scene.convertBlenderCollection(bpy.data.collections[str(COLLECTION_NAME)], bool(ASNC_LOADING))
Oopss…it doesn’t work either
It says: nothing indicated
Was able to solve it my self
It turns out that you just have to make sure there isn’t a light source in the collection you want to take to the other blend file
This is odd behavior. For me when I run my script at BGE runtime, my lights get converted with no errors.