Python Help - object.location does not move child empty objects or does in a weird way

Hello, I’m trying to assemble a robot in python by taking the parts and putting them together. My leg object for example has 2 empty objects as children for placement of other parts. When i copy this object and move it to “Root” object in the world center, the empties move in a very weird way. Any idea of what’s happnening??

import bpy
from random import random

def get_children(ob):
    return [ob_child for ob_child in Object.Get() if ob_child.parent == ob]

#Get the objects in the materials collection and a random material from there.
PRIMARY_MAT = MATERIALS.objects[RAND_PRIMARY_MAT].data.materials[0]

#select your collection by name (in this case the collection named "Collection")
headCol =["PILOT"]
frontCol =["FRONT"]
topCol =["TOP"]
itemCol =["ITEM"]
legCol =["LEGS"]

#clean whatever's there
for obj in MECHBUILD.objects:, do_unlink=True)

numHead = len(headCol.objects)
numTop = len(topCol.objects)
numFront = len(frontCol.objects)
numItem = len(itemCol.objects)
numLeg = len(legCol.objects)

#Generate random number 
randHead = round(random()*(numHead-1))  
randTop = round(random()*(numTop-1))  
randFront = round(random()*(numFront-1))  
randItem = round(random()*(numItem-1))  
randLeg = round(random()*(numLeg-1)) 

headObj = headCol.objects[randHead]
topObj = topCol.objects[randTop]
frontObj = frontCol.objects[randFront]
itemObj = itemCol.objects[randItem]
legObj = legCol.objects[randLeg]

#creat a copy of the object and link it to the collection 
#newHead = headObj.copy()

newLeg = legObj.copy() =
for child in legObj.children:
    newLegChild = child.copy()
    newLegChild.parent = newLeg = "NEWLEG"[1] = PRIMARY_MAT[2] = SECONDARY_MAT

newTop = topObj.copy() =
for child in topObj.children:
    newChild = child.copy()
    newChild.parent = newTop = "NEWTOP"[1] = PRIMARY_MAT[2] = SECONDARY_MAT

newFront = frontObj.copy() = = "NEWFRONT"[1] = PRIMARY_MAT[2] = SECONDARY_MAT

newItem = itemObj.copy() = = "NEWITEM"[1] = SECONDARY_MAT

newLeg.location =['Root'].location

newTop.location =['NEWLEG'].location
#newHead.location =['TRANSFORM_PILOT'].location
newFront.location =['NEWLEG'].location
newItem.location =['NEWTOP'].location
modifier = newItem.modifiers["Mirror"] # Get existing modifier with name "Array"
modifier.mirror_object = newTop```

define “moves in a very weird way”. unless you’re experiencing some critical bug in Blender nobody else has seen, it’s moving exactly in the way you’ve told it to move- so this weirdness is entirely subjective. We need your description of what is happening to help diagnose the problem.

What it does is, when it copies the robot part and its children, when I change the location of the parent(the part itself) the children don’t stay in the same relative position as you would expect with parenting.

It’s structured like this:


  • Torso Socket
  • Holster

Curtis Holt has a number of generators that do what you’re attempting to do and they work fine so I don’t think there’s a bug with Blender.

Post a blend that works with your script that demonstrates the wrong behavior.