KX_Scene (first argument): object must be in an inactive layer

Hi, I am doing this tutorial : http://www.youtube.com/watch?v=cklrL9LD3XI&lc=hsGrEBKxn9B7FIAK5W00ut2hdpd5ba5j807TxKOb_bk

Blender Game Engine Started
[Spawner, VBlock, HBlock, Camera, Tunnel, default__cam]
Spawn:: HBlock
Python script error - object ‘Spawner’, controller ‘Python’:
Traceback (most recent call last):
File “/home/case/laptop3D/blendergametut/tunnel1.blend/SpawnScript.py”, line 18, in spawn
ValueError: scene.addObject(object, other, time): KX_Scene (first argument): object must be in an inactive layer

and I’m getting this error KX_Scene (first argument): object must be in an inactive layer, I’ve tried varies different ways to reference to the HBlock / VBlock and nothing seems to be working, everything in my file is all on the first layer, so I dont know what it is talking about.

from bge import logic
import random

def spawn():

scene = logic.getCurrentScene()

print(scene.objects)

blocks = (scene.objects["VBlock"], scene.objects["HBlock"])

block = random.choice(blocks)

print("Spawn::" ,block)

new_block = scene.addObject(block, scene.objects["Spawner"])   
new_block.setLinearVelocity([0, 180, 0])

Its saying the object needs to be on a different layer than the ones visible(Exactly what it says). The problem is the fact that its on the same layer as everything else. Try moving it to a different layer that isn’t visible, then try again :slight_smile:

now it complains that the object is not in the list.

As in this line ’ blocks = (scene.objects[“VBlock”], scene.objects[“HBlock”])

VBlock key is not in the list

Its saying that the object is not in the list scene.objects. This is because the objects don’t exist yet as they are in an inactive(Not yet used) layer. There are two ways to fix this :slight_smile:
1:
Just reference the objects by name(blocks = (“VBlock”, “HBlock”)). The function automaticly finds the object based on this name :), or
2:
Now that the objects are in an inactive layer, you must find them using scene.objectsInactive, (blocks = (scene.objectsInactive[“VBlock”], scene.objectsInactive[“HBlock”]))

Hope that helps :slight_smile:

Just for clarification:

In terms of logic there are no layers. There are active and inactive objects.

Per definition (and handling) objects are active if they reside in an active layer (in Blender) and inactive otherwise. If you want you can see the inactive objects masters/template/originals to make copies from. So inactive layers are like a secret storage ;). You do not do anything with it unless you need a new object. The problem in using active objects to copy from is … they might be gone in the meantime, which will fail the copy operation ;).

In post #3 the bge is telling you that active objects with this name can’t be found in this scene. As you made them inactive (see above) you can find them in the list of inactive objects KX_Scene.objectsInactive. I hope your code is making a copy of them only (via addObject or AddObjectActuator).

I hope it helps