# How to remove an object in bge?

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

print(scn.objects)

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


How can I remove Cube.001 from that list?

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