Python List: from_id

from_id(ID)
  • Returns the game object that belongs to the ID.

Return Type:

  • KX_GameObject or KX_Light or KX_Camera
ID:
  • integer or long variables.
Note:
  • Integer range:  -32,768 to 32,767
     
  • Long variable range: -2,147,483,648 to 2,147,483,647
Sample Code: Part 1

###############  getting the object id

# import bge
import bge

# get current controlleer
cont = bge.logic.getCurrentController()

# get object controller attached to
obj = cont.owner
 
# get the object ID
objID = id(obj)

# save object ID as global variable
bge.object_ID = objID

Sample Code: Part 2

###############  getting the object from object id

# import bge
import bge

# get current scene
scene = bge.logic.getCurrentScene()

# get object list
objList = scene.objects

# get saved object ID
objID = bge.object_ID

# use the object ID to get the game object
obj = objList.from_id(objID)