I have two objects

A a box


B a sphere.

I want to make B A's child.

how can this be done in the BGE, using python?


1 Answer 1



import bge

cont = bge.logic.getCurrentController()
own = cont.owner
scene = own.scene

objA = scene.objects["objA"]
objB = scene.objects["objB"]


setParent(parent, compound=True, ghost=True)

Sets this object’s parent. Control the shape status with the optional compound and ghost parameters. In that case you can control if it should be ghost or not.

  • parent (KX_GameObject) – new parent object.

  • compound (boolean) – whether the shape should be added to the parent compound shape.

    • True: the object shape should be added to the parent compound shape.

    • False: the object should keep its individual shape.

  • ghost (boolean) – whether the object should be ghost while parented.

    • True: if the object should be made ghost while parented.

    • False: if the object should be solid while parented.

Source: Blender 2.79 API Documentation, bge.types.KX_GameObject section

  • $\begingroup$ thanks this is perfect. $\endgroup$
    – Frederick
    Aug 5, 2019 at 19:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.