3
$\begingroup$

I have several scenes that will be using the same objects over and over. So I created a directory scene so I can pull objects to their places (while the game is runing) with no problems. But I don't know how to add objects from another scene. Can someone tell me the code for this or if it is even possible.

This is in the game engine and I would like to know if there is a way to add an object in game, while the original is in an entirely different scene. For instance if I wanted to add a character model called "Bob". "Bob" is in scene "directory" I want him to be added at the location marked by object "point".

$\endgroup$
  • $\begingroup$ Duplicate: How to add a game object to another scene at a specific position? $\endgroup$ – David Dec 8 '16 at 2:26
  • $\begingroup$ Mr David. I first tried the code that was mentioned here several times. But I get the error that the object I am trying to add did not match any game object in the scene. And I get a bright white box that takes up most the screen. I made another question because I thought I might get a solid answer not a reference to what I already tried $\endgroup$ – c0mlink Dec 8 '16 at 3:18
2
$\begingroup$

Scene dependencies

You can't copy game objects across scenes. All template objects have to reside in the scene you want to add them to.

Linked objects

Blender allows to link objects (and object data) across scenes. The BGE will load them as individual copies. This allows you to get a single (Blender) object as copies within your BGE scenes.

Ensure they are still placed within hidden layers that you can use them as temple object on add object.

Scenes interaction

These objects are individual Objects and have no relation to each other (beside they look equal). This means when you want to transfer any "manipulation" from one scene to the other you apply a similar manipulation to this other object.

Example 1:

In scene A you show object cube. When clicking on it you want to create such a cube in scene B.

So you need to tell scene B, that it should create a cube at a certain location.

I suggest you send a message from scene A to an "object builder" object in scene B. This object builder creates the desired cube at the desired location. You should provide enough information that this will be successful. So you need to tell that it should be a cube and not a sphere. You should tell what location the cube should get and so on.

Example 2:

You moved the copy of a sphere from (0,0,0) to (10,0,0) in your scene A. Now you need to apply a matching operation to the according sphere of scene B.

So you tell the other scene to "move sphere" to an according position. Be aware it does not need to be the same position as in scene A.

Conclusion

I'm not sure if that explains enough.

Each single scene is responsible for itself. It should know the templates it can use and it adds the copies by itself.

Avoid trying to add objects from other scenes. This creates unnecessary dependencies. Better tell objects of the other scene what you want. This way the scene can care of it self.

Messages are a good way of inter-scene communication. They do not establish strong dependencies (means it does not matter if the other scenes exist). It works well even with multiple listening objects in any number of active scenes.

You can still access complex data from a custom python module. This way you get scene independent shared data that can be used as long as your game runs.

$\endgroup$
1
$\begingroup$

Say your object is "Cube":

obj = bpy.data.objects["Cube"]
bpy.context.scene.objects.link(obj)
$\endgroup$
  • $\begingroup$ consider adding a little more explanation to help people new to Python out a bit $\endgroup$ – VRM Dec 8 '16 at 0:17
  • $\begingroup$ My fault completely but this is not what I am looking for as it dose not add the object in game. Witch I neglected to mention $\endgroup$ – c0mlink Dec 8 '16 at 0:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.