Skip to content

KX_Scene

Base class: EXP_PyObjectPlus

An active scene that gives access to objects, cameras, lights and scene attributes.

The activity culling stuff is supposed to disable logic bricks when their owner gets too far from the active camera. It was taken from some code lurking at the back of KX_Scene - who knows what it does!

from Range import logic
# get the scene
scene = logic.getCurrentScene()
# print all the objects in the scene
for object in scene.objects:
print(object.name)
# get an object named 'Cube'
object = scene.objects["Cube"]
# get the first object in the scene.
object = scene.objects[0]
# Get the depth of an object in the camera view.
from Range import logic
object = logic.getCurrentController().owner
cam = logic.getCurrentScene().active_camera
# Depth is negative and decreasing further from the camera
depth = object.position[0]*cam.world_to_camera[2][0] + object.position[1]*cam.world_to_camera[2][1] + object.position[2]*cam.world_to_camera[2][2] + cam.world_to_camera[2][3]

@bug: All attributes are read only at the moment.

The scene’s name, (read-only).

Type: string

A list of objects in the scene, (read-only).

Type: EXP_ListValue of KX_GameObject

A list of objects on background layers (used for the addObject actuator), (read-only).

Type: EXP_ListValue of KX_GameObject

A list of lights in the scene, (read-only).

Type: EXP_ListValue of KX_LightObject

A list of cameras in the scene, (read-only).

Type: EXP_ListValue of KX_Camera

A list of texts in the scene, (read-only).

Type: EXP_ListValue of KX_FontObject

The current active camera.

Type: KX_Camera

The override camera used for scene culling, if set to None the culling is proceeded with the camera used to render.

Type: KX_Camera or None

The current active world, (read-only).

Type: KX_WorldInfo

The scene’s 2D filter manager, (read-only).

Type: KX_2DFilterManager

True if the scene is suspended, (read-only).

Type: boolean

True if the scene allow object activity culling.

Type: boolean

True when Dynamic Bounding box Volume Tree is set (read-only).

Type: boolean

A list of callables to be run before the render step. The callbacks can take as argument the rendered camera.

Type: list

A list of callables to be run after the render step.

Type: list

A list of callables to be run before the drawing setup (i.e., before the model view and projection matrices are computed). The callbacks can take as argument the rendered camera, the camera could be temporary in case of stereo rendering.

Type: list

A list of callables to run when the scene is destroyed.

@scene.onRemove.append
def callback(scene):
print('exiting %s...' % scene.name)

Type: list

The scene gravity using the world x, y and z axis.

Type: Vector((gx, gy, gz))

The number of fragments of broken objects kept alive in the scene; past it the oldest are removed. Starts with Scene > Game Physics > Max Debris. 0 means no limit. Lowering it removes the extra pieces at once.

Type: integer in [0, 100000]

explode(position, radius=5.0, force=20.0, upBias=0.3, occlusion=True, mask=0xFFFF, ignore=None)

Section titled “explode(position, radius=5.0, force=20.0, upBias=0.3, occlusion=True, mask=0xFFFF, ignore=None)”

Radial impulse on the dynamic objects around position, falling to zero at radius (force * (1 - distance / radius)). Destructible objects hit above their KX_GameObject.breakImpulse break and their pieces are pushed, sharing the impulse by mass. Explosive objects hit above their Impact Impulse (with Chain Reaction on) detonate on the next frame.

  • position: The center of the blast.
    • type: 3D Vector
  • radius: The distance the blast reaches.
    • type: float
  • force: The impulse at the center.
    • type: float
  • upBias: How much the push is tilted upwards, 0.0 is straight away from the center.
    • type: float
  • occlusion: If True, static geometry between the center and an object shields it.
    • type: boolean
  • mask: The collision groups reached.
    • type: bitfield
  • ignore: An object or a list of objects left out.
    • type: KX_GameObject or list

Returns: The objects reached (not the new pieces).

Return type: list of KX_GameObject

Adds an object to the scene like the Add Object Actuator would.

  • object: The (name of the) object to add.
    • type: KX_GameObject or string
  • reference: The (name of the) object which position, orientation, and scale to copy (optional), if the object to add is a light and there is not reference the light’s layer will be the same that the active layer in the blender scene.
    • type: KX_GameObject or string
  • time: The lifetime of the added object, in frames (assumes one frame is 1/50 second). A time of 0.0 means the object will last forever (optional).
    • type: float

Returns: The newly added object.

Return type: KX_GameObject

Removes the scene from the game.

Restarts the scene.

Replaces this scene with another one.

  • scene: The name of the scene to replace this scene with.
    • type: string

Returns: True if the scene exists and was scheduled for addition, False otherwise.

Return type: boolean

Suspends this scene.

Resume this scene.

Return the value matching key, or the default value if its not found.

Returns: The key value or a default.

Draw debug visualization of obstacle simulation.

These items exist in the engine but were not in the Range documentation. The ones marked new in Anastacio were added by Anastacio Engine.

method

Creates now an object that was left out at load time by the Convert option (and its unconverted children). It goes to objects if it is on an active layer, otherwise to objectsInactive (ready for addObject). An object already converted is returned as is.

Returns: KX_GameObject

method

Starts the scene native Cutscene. Returns True on success.

Returns: bool

method

Releases a Cutscene Wait Trigger event waiting for name. True if it was waiting right now; otherwise the trigger is kept for the next Wait Trigger with that name. A message with subject name does the same.

Returns: bool

method

Restarts the active Cutscene and removes the objects it created.

method

Stops the Cutscene and removes the objects it created.

attribute · read-only

List of the scene sound objects (KX_Speaker).

attribute

List of functions called every frame on the parallel logic thread. Same usage as pre_draw.

new in Anastacio attribute · read-only

Names of the objects that can still be created with convertObject().

attribute · read-only

Sun light linked to the World (sky sun position), or None.