Linking the sensor of an object created in game to actuators of other created objects

So let’s say we want this to happen.

1). Object A creates object B using the add object actuator.
2). Object C is created by Object A
3). In the hidden layer, I link Object B’s sensor and controller to actuators on Object C
4). (the problem), when Object B and C are created together, object B’s sensor doesn’t activate Object C’s actuators even though they’re linked.

Why won’t it work? Is it a bug or not implemented yet, if the former can this be fixed, if the latter can this be implemented? This here I was wanting to use to optimize a game demo with the sensor in a master object because only the master object’s sensor is checked instead of checking a sensor in every object. This is critical in speeding up logic among many like-objects, so I’d like it to work.

When an object is dynamically created, all the links between logic bricks of this objects and its children are preserved: they will link the replicated object and its replicated children. The same is true when you replicate a group.
However, all the logic bricks that point to an object outside the group will still point to that original object after replication. In your example, the replicated object B is linked to the original object C that sits in its inactive layer and can’t do anything.

To make your example work, put B and C is a group and replicate an empty that has dupligroup option set (because there is no direct AddGroup actuator), this will instantiate B and C at the same time and preserve their logic brick connections. Note that the empty is only needed to instantiate the group, you can make it die immediately with a endObject actuator.

Hope this is clear.

Thanks, but I’m looking at something more complex here dealing with created objects.

Say you have a level with 2 sections, section A and section B.

-Section A has several types of physics objects, Section B has lots of barrels.
-The different objects in section A end themselves and create the same type of object, but is in a hidden layer (Boxes create boxes, barrels create barrels ect…)
-You start in Section A, Section B’s barrels slow the game down so you make all the barrels create an empty and then end themselves.
-One barrel in Section B creates a master empty.
-When you hit an invisible plane and send a message, Section B’s master empty, (the one with the sensor), tells the rest of the empties to create a Barrel and end themselves.
-The Master empty then goes and creates a master barrel.
-When you leave section B, the master barrel, (again, the one with the sensor), tells all the barrels to create an empty and end themselves.
-The master barrel creates the master empty and you know what should happen when you re-enter section B.

-When you leave and enter section A, it’s the same thing only you deal with the master object telling several different objects to create several different empties and the master empty telling several different empties to create several different objects.

I just need to know how I can use the (master object the only one with a sensor) idea to do object swapping with minimal sensor checking. A .blend file, Ben2610 would be nice to have to help study how to do this, I tried doing this with object groups but I couldn’t get it to work exactly right.

I could swear there was some python function which got the name of a just-created object. Can’t seem to find it in the API though.

From in PyDocs:

    def getLastCreatedObject():
        Returns the last object created by this actuator.
        @rtype: L{KX_GameObject}
        @return: A L{KX_GameObject} or None if no object has been created.

A quick example:

addObj = GameLogic.getCurrentController().getActuator("add")

obj = "Cube"


lastObj = addObj.getLastCreatedObject()


I’m not sure if it helps you much or not.