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.
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.
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
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 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)
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 -.-
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.