How to refer to object children when you have many instances of that same object.

Hello,

I have the folowing scenario: i want to create a random number of identical robots (objects) on the surface of a plane. Every robot has a camera (the robot is the parent). The plan was to add with addObject instances and then let them follow some rules (harvest, scan etc). The probleam was that i referenced the camera of the robot by name so evry instance uses the first camera not it’s child camera.

Is there a simple way to solve this issue? How to refer to object children when you have many instances of that same object.

Thank you!

sure Python only!

when working with instances or AddObject NEVER reference by name. They share the same names.

Use object references instead. E.g. objRef = addObject(…)
If you have any object of the instance you can navigate through the object tree (object.parent/object.children). You just need a reference (e.g. collision sensor or whatever.

I hope it helps

Sorry i should have been more specific, i am searching for a python solution.
How can i get a reference of a child camera (lets say the camera has a cube parent) when the code i am runing is on the cube. I know that i can get a list of all the children but if i have 2 cameras? Won;t the names differ for every instance?

Monster offered a Python solution… As monster said, all added objects share the same name as the hidden object that they are based on. You need to reference these objects directly rather than by name. addObject returns a reference to the added object so you can store the object reference when you add the objects to distinguish between them newObj = scene.addObject(“object”) or addedObjList.append(scene.addObject(“object”))

If each object has multiple cameras and each camera has a unique name then you can use something like object.children[“cam1”] and object.children[“cam2”] instead of using scene.objects[“cam1”] etc.

If you want to access the children of an added object from a script on that added object then all the children will have the same name so simply use the name of the children with object.children[“childName”]

i understand now :slight_smile: thank you very much to you both