Scene: addObject

addObject(object)
  • Instantly adds a game object to the scene

object:
  • game object being added
  • Type:  KX_GameObject or string

Note:

  • The source object must be on a hidden layer

  • Object is added with the original rotation, scale and position of the source object

addObject(object, other, time)
  • Instantly adds an object to the scene

object:
  • game object being added
  • Type:  KX_GameObject or string
other:
  • Object that is being used to add the new game object
  • Type:  KX_GameObject or string
time:
  • Lifetime (in frames) of the object being added
  • Type:  integer
  • 0 = forever

Note:

  • The source object (object being added) must be on a hidden layer
     
  • Object is added with the original scale of the source object
     
  • Object is added with the rotation and at the location of other: addObject(object, other, time)
Sample Code

################## instantly add a game object

# import bge
import bge

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

# get the game object named Tree
object = "Tree"

# instantly add Tree
scene.addObject(object)

Sample Code

################## instantly add a game object

# import bge
import bge

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

# get the game object named Bullet
object = "Bullet"

# get the game object (an Empty) named Rifle_Muzzle
# I'm using an Empty parented to a game model of a rifle

other = "Rifle_Muzzle"

# set time to 500 frames
time = 500

# instantly add bullet
scene.addObject(object, other, time)