Load objects from other scene without linking?

Hi everyone

Is there a way to spawn objects from other scene to current scene without linking all objects of that state to the current one?

Kinda like:

Scene A has Pikachu
Scene B has nothing

If Pikachu needs to appear in B, you most have to link the Pikachu object to B… But is there a way to just load it right away from Scene A ?

Thank you in advance

Yes, and it is really useful, of this manner you can load on file, and spawn an object of that file in the moment you want.

You can’t load anything from another running scene.
You can load objects from scenes from a .blend file via LibLoad.

You can assign the object to a group and instantiate the group in an hidden layer to addObject() copies of it. It does not matter if you link or append the group.

thanks carlo and Monster

How could I just add everything from 1 other file, and reveal them even like the order i made in that other file?

For example (external blendfile)

Layer 1 (shown): pikachu
Layer 2(hidden) : pikachu cloth

after adding them with python, those still have the same status like that , in main blendfile?

When you libload, any visible objects in the loaded file will be visible, whilst anything on a hidden layer must be added using addObject.

This only applies to loading using the “Scene” loading mode.

thanks agoose77

can you please provide an example code for me? i never use libload before. So if we loads the scene, the whole scene is loaded? I only need to add the main character , (many objects are parented to it). Is there other way for that?

When a scene just starts, the libload should function right away

Yes, that works.

It does not… I used this

from bge import logic , events

def keyHit(key_code):

status = logic.keyboard.events[key_code]

return status == logic.KX_INPUT_JUST_ACTIVATED

def load():

logic.LibLoad("D:\MUSIC BLENDER\other/libfile.blend","Mesh")

def replace():

scene = logic.getCurrentScene()
cube = scene.objects["CharacterCube"] 

cube.replaceMesh("Head")

def free():

logic.LibFree("D:\MUSIC BLENDER\other/libfile.blend")

functions = [free, replace, load]

def main():

if keyHit(events.SPACEKEY):
    
    if len(functions):
        fn = functions.pop()
        fn()    

lHeadl is a children of an armature, with is parented to CharacterCube

I wanted the Cube to change to CharacterCube but It did not work, but when i change replacemesh Head, it does change. How can solve it T.T

When posting code use [ code][ /code], can you post a blend file please?

I try to use your code (I really don’t undertand why it uses len(functions)), it does work. exactly what do you want to do? spawn the complete character? (CharacterCube, and its children), if this is what you wan to do, load the file by using “Scene” type, and use addObject for add “CharacterCube”.

i just copy this script from Goran’s video. i do not understand what it is really meant in the script T.T

this rar file contains 2 blend files. open the test.blend and just use space to do the functions. the libfile.blend has a monkey head

The example works for me, I just change some lines to to the path of the file relative to file’s path. what problem are you getting?

The same function doesnt work for me when i want the script to load 1 Cube object (CharacterCube) to my project, that object is the parent of very many objects ( character mesh, character armature, some planes, some empties, ). In the console it says like KX… does not match… something.

when i just let the base cube remesh to the head of character, or hair, eye, cloth, it works…

well, a screenshot of the error? You say that after load the file and use addObject to add one object from the loaded file (which is parent of other objects), it appears an error? try changing the loading type from “Mesh” to “Scene” (and leave the objects in a hidden layer in the loaded file).


T.T i just changed the line cube = scene.objects["…"] to 3 different objects. as you can see there

That’s because there’s no any Mesh named “Main”. Are you sure that the meshes have the correct names?

Main is the armature of the character, i guess remesh function doesnt work with armatures. But there as you see the CharacterCube (parent of Main) is spawed. but the armature doesnt follow it to the scene (including lower children)

yes, replaceMesh only works with meshes.

Well, It’s supposed that the “CharacterCube” will include its children when you spawn it. I exactly don’t know what that’s happening.

poor me T.T i tried replace replaceMesh to addObject. but it says there is no function called addObject @.@

You are trying to spawn “CharacterCube” by replacing the mesh of another object by CharacterCube’s mesh? that will not work, it’s even not “spawn”, you are just replacing one mesh. AddObject is a function of an scene class, for example: bge.logic.getCurrentScene().addObject(“object to add”, “base object”)

bge.logic.getCurrentScene().addObject(“object to add”, “base object”)

use that as 1 line O.O ?