Python: Get an object from another scene?

Hi, I’m trying to get a 2d-like object on an overlay scene to follow a moving object on a main scene. Logic bricks only give me the option of sending it a message. I don’t think I can do a parent across two different scenes.

I thought that if I used Python, I might be able to get the 2d object to follow the object on the other scene by using something like:

from bge import logic
<b> Note: The following line is NOT an actual blender function</b>
otherscene = logic.getAnotherScene('Scene')
scene = logic.getCurrentScene()
2dob = scene.objects['2dobject']
3dob = otherscene.objects['3dobject']
3dpos = 3dob.worldPosition
<b> The following line probably needs tweaking.</b>
2dob.worldPosition = [3dpos, 3dpos, 0]




from bge import logic
as = logic.getSceneList()
cs = logic.getCurrentScene()
os = as.Scene
thpos = cs.objects['2dobject']
ppos = os.objects['3dobject']
thpos.worldPosition = ppos.worldPosition

It didn’t work. :frowning:

‘as’, as you have defined it, is a list returned by the ‘getSceneList’ function of the logic module. The list consists of scene objects - it should be something like:

[GameScene, GUIScene]

The last added scene should be the GUI scene, since the first would be the game scene you started with. So, you can use

os = as[GUISceneName]

to find the GUI scene.

Thanks for the reply.

I tried editing the script with that, but it still didn’t work.

Any hidden syntax I don’t know about?

Did you ever figure this out? I’m trying to do the same thing.

Easy i beleive.

import bge

scenes = bge.logic.getSceneList()

my_scene = [scene for scene in scenes if"My Scene"][0]
object = my_scene.objects['My Object']

Agoose is right - there was a mistake in my code. :stuck_out_tongue:

This is the story of my life!