Dynamic parent in game engine?

I want to create objects with the EditObject/AddObject actuator and parent the new object to an empty. I have tried to copy the position of the empty to the object but it has a litle time delay.

:frowning: Any ideas?

Move the empty a frame sooner than you want to :slight_smile:

Unfortunately, this is yet another feature that didnā€™t make it. Hopefully rectified soon once the source gets back for real.

Didā€™nt get it???

Iā€™m using a addObjectActuator to add an object from a hidden layer into the active layer. When this new object is created i want it to be parented to an empty in the active layer. What iā€™m doing now is sending a message to the new created object to activate the script below

from Blender import Object
import GameLogic

empty = Object.get(ā€œemptyā€)
newObject = Object.get(ā€œnewObjectā€)

empty.makeParent([newObject])

----The problem is that this code is parenting the empty in the active layer to the original object in the hidden layer, not the new created object!!!

I would really apreciate some help on that!!!
Iā€™M GETTING CRAZY WHITH THIS!!! :<

What I was saying in my post, is you cannot parent added objects to anything, as all parented objects use the same name. Also, most python functions outside the GameBlender module do not get updated in realtime, but only when you refresh the whole scene.

So what you are trying to do is not possible.

Sorry, i always see this line in a lot of code.

import GameLogic

You do not need to include it. It is auto included :stuck_out_tongue:

what do you need the parenting for?

i agree that it would be nice if it worked, and think that it should and can be corrected, but at least some things can be worked around in Python, like having several objects follow one just by issuing the same commands to themā€¦ like this:


def move(self, direction):
        if direction=="stop":
            self.move_z=0
        
        if direction=="forward":
           self.move_z = self.move_z - 0.01

        if direction=="backward":
            self.move_z = self.move_z + 0.01

        self.move_act.setDLoc(0, 0, self.move_z, 1)
        act1(self.move_act)

        for clones in self.allclones:
           for clone in clones:
               self.clonemoveact=clone[1].getActuator("move")
               self.clonemoveact.setDLoc(0, 0, self.move_z, 1)
               act1(self.clonemoveact)

might something like that help? other than that, the parernting code should be looked at wrt go the game engineā€¦

~Toni

I need the parenting to make an added object follow the main character of a game iā€™m making.

Itā€™s going to take a while to test your code, antont.
I have to change some things on the scripts that are already done, but
I think your code is just what i needed. :smiley:

Ok, that is surely doable - just read the position of the main character and set the followerā€™s accordingly, or do like i in the above that the follower makes the same movements as the main.

~Toni

The code is better!!! :smiley:

If I remember right Erwin did add a getLastCreatedObject or similar function to the add-Object Actuator, so maybe that will help.

Carsten.