1
$\begingroup$

I have the following piece of code to add an object to a scene in bge. When I use endObject(), the object disappears from the scene, but I can still see it in scn.objects. How can I remove it from scn.objects?

import bge
import bpy

cont = bge.logic.getCurrentController( ) 

own = cont.owner
scn = bge.logic.getCurrentScene( )
ob = scn.addObject("Cube.001", "Empty", 0)
ob.endObject()

print(scn.objects) 

# the output is [Empty, Cube, Lamp, Camera, __default__cam__, Cube.001]

How can I remove Cube.001 from that list?

$\endgroup$
  • $\begingroup$ Please do not mix bge and bpy code. These are APIs to two different applications. $\endgroup$ – Monster Jan 12 '16 at 5:09
2
$\begingroup$

With KX_GameObject.endObject() you request the game object to be deleted.

This call does not remove the object from the scene at that time.

The object will be removed by the BGE after the actuators where executed. It takes effect within the next frame.

Imagine you put a label on the object ... "please remove" (or you put it in the trashcan). The janitor will remove it when cleaning the room.

Remark: It does not matter if you use endObject() or the EndObjectActuator. The behavior is the same.

Care the timing

$\endgroup$

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.