Load objects from other scene without linking?

Replace the line:

cube.replaceMesh(“CharacterCube”)

by:

scene.addObject(“CharacterCube”, cube)

The first value of the addObject function is the object you want to add to the scene, the second line is one object what transforms will be used for the new object.

Set the second value as the object you was trying to replace mesh.

have you seen some python or bge python tutorial?


-.- Something is not ok with using libload… sigh… Ya i watched many tutorials but i understand very little with programming.

Looks like you don’t change the data type of the LibLoad to “Scene” (I told you it two times…).
Change the line “Mesh” word to “Scene” in line 12.

weeee it works now YEEEY!

thanks carlo,
hm i would like to ask if you can help me to modify the code so that it just adds the object directly , 1 time as the scene begins? . T.T i dont know how

I made one very simple example (with comments line):
LibLoad example.zip (159 KB)
Hope you learn from it!

But if you will add the object only one time in all the game, I recommend to just put the object in a visible layer (external file) and libload it (without use addObject) in this way you don’t have to use addObject to add it.

thanks alot carlo

the script works well in the scene. but when i view that scene as an underlay scene. it doesnt show. do you know why it is? o.o

It works for me, do you put a camera in the overlay scene? is your script in the main scene and you want to add the player in the another scene?

i am making a music game. So i use the main scene as the area where the game spawns arrows and calculates beat timing. From that scene i use ‘add underlay scene’ to reveal dancer and environment. Because i have different environment ( dancing stages) for the character, thats why i use libload to spawn the character easily to every scene.

The script is attached to the camera of underlay scene

I test the script in a overlay scene, and it works. I don’t know what is happening in your case, appears an error in the console?


it only loads the character in underlay scene… from the main scene it shows this.

The script have a little mistake, replace the line: 27 with: baseObject.endObject(), but it’s no really necessary delete that object. But I don’t think that’s the problem, there’s another error below, looks like the script is execute twice.

Do you put the always sensor attached to the script in tap mode? I get the same error if I do that, or add one line that check if the always sensor is positive.

You’re calling endObject on a string. Instead, you need to call endObject on the baseObject variable.
You’re also not checking whether the triggered sensor is positive, so your script is running twice, during which time the file is already open in memory on the second invocation. Add a sensor positive test (if not sensor.positive: return) where sensor is the reference to the triggering object sensor, and you use the appropriate new line formatting.

thanks agoose77

but i dont know how to put those lines into that code T.T it was written by carlo …

Thanks to carlo697 for the file, which I modified to demonstrate these changes.
I removed the spawn function as it was relatively close to the BGE API.
Take some time, if you will, to look at the comments within the file, and gain an understanding of what it is doing.
player.zip (160 KB)

thanks agoose and carlo

hm the modification works too, but from the main scene it still doesnt show the loaded objects… just the underlay scene with background where it is supposed to show that object… I guess there is something wrong with something else… I will try to take a closer look somehow -.-

Could you provide a simple form of your file, and ensure you’re calling this python controller from the appropriate scene?

I tried to change some logic bricks and found the problem. Every underlayscene has an empty that receives messages to change into other scenes. From the main scene i have some property logic bricks which do : Number - and - Msg (sceneID). When i just remove the logic for changing the very first scene. It does load the character right away.

This is how i want it to behave

I used your blendfiles to immitate the problem. There are 2 scenes. 1 is with the monkey head and 1other has an UV sphere.

I build the logic in the main scene to send messages to an empty that exists in both of the underlay scenes. press space to toggle the property.

Please use the forums for uploading the file, or dropbox, as other sites are both a pain to download from, and rather untrustworthy

mediafire then

It’s only 150kb or so, next time just use the forum to upload!