parenting and Python order of execution

ok, so does python or blender execute each line of code as it is read or does it do some reorganization when using parent or object.applyRotation(vector,0)?

here is my problem, I am parenting a group of objects (bricks) to another ghost object which I place at their mean location. I then parent that ghost object to my character and walk around. When I have the objects (bricks) where I want them (i.e. like stacking lego bricks on top of each other) I run a definition that snaps the ghost object to 1/4 BU and the orientation to the nearest 15 degree increment. Then before the script finishes running I remove all the children of the ghost object and end the script.

The problem seems to be that the ghost object is loosing its children THEN snapping its position and orientation, which is backwards to the way I wrote the script.

So what is going on!!! :frowning:

Attached is a simple .blend to illustrate my problem. I have put notes in with the code to draw attention to my problem and explain my methods.

Thanks again for any insight :slight_smile:

Attachments

simple parenting with rotation test.blend (250 KB)

I’m not sure if the scene graph is updated between
own.applyRotation([0,0,45*pi/180],0)
and
deParent(own)

most likely this is your problem. BTW. I would expect it to be updated too.

What you can do is to add an additional state and get following sequence:

state 1 (frame t): blocks parented + space pressed -> correct orientation -> go state 2
state 2 (frame t+1): blocks parented + orientation already corrected -> unparent -> go to state 1

Hey Monster, so states can be used in python? I thought that was just something handy for logic bricks. I was hoping there would be a way to fix this using like scene.update or something in between the applyRotation and deParent parts of my code. If not that is cool, I’ll just learn more about using states :smiley:

Attached is a sort of other way of doing it using a separate script. Though I hate having a million scripts laying around it does work :stuck_out_tongue: :frowning:

Thanks for you insights and I am glad I am not alone in expecting the first .blend to function properly, though sad it doesn’t

Attachments

simple parenting with rotation test SOLVED.blend (251 KB)

Glad to help :slight_smile:

Just some hints:

If you connect an always sensor (no pulses) to your CharEmpty. The blocks will be created right at start of the scene (I’m not sure if you need that).

If you have a lot of scripts it might be worth to convert them to modules and use the module mode of the python controller. This allows a lot more organization, as you can collect multiple different controller calls into one file. (It is faster too :D).