Parent Actuator Help

Okay, so here’s how it goes. I run the game engine. I press a button to add an object that’s from another state, and then I press another button to add another object that is in another state. The second object has the parent actuator that parents it to the first object that I added.

The problem is that the child object won’t parent to the first object, and I don’t know why. The always sensor is set to “level” on the child object. I checked everything else and it still won’t work. I also tried it in a simpler setup and it still didn’t work. Can someone find me a solution? Is this a glitch?

shift to add cube
enter to move cube
a to add child

It doesn’t work!

Attachments

test.blend (129 KB)

Bump. (10letters)

The initial configuration refers the objects at the inactive layer. Added objects are not known. Therefore they can’t be referenced with this method.

See TrackTo and added Objects. it deals exactly with this problem but with another actuator type.

You need to update the parent actuator via Python controller. Alternative you can perform the parenting directly in the code.

One possible method:

Demo.py


def addAndParent(cont):
  if not allPositive(cont):
    return

  for actuator in cont.actuators:
    addAndParentObject(actuator)
 
def addAndParentObject(actuator):
  try:
    addedObject = actuator.instantAddObject()
  except AttributeError:
    return

  addedObject.setParent(actuator.owner)

def allPositive(cont):
  for sensor in cont.sensors:
    if not sensor.positive:
      return False
  return True

Usage:
at the first object to be added!
any sensor (e.g. keyboard sensor)
-> Python controller Module: Demo.addAndParent
. —> AddObjectActuator (one or more)

You do not mention what object adds the new object. I assume the first added object should add the second one. Otherwise another method would be necessary.

Please keep in mind this method does not activate the actuator.
The object is added when executing the Python controller.
After that the new object is parented to the owner of the addObjectActuator.

I hope it helps