Best method for accessing objects from python?


So say I have a low poly mesh for handling collisions, and an armature with a mesh skinned to it. I am writing a script to try and handle the moving of the collision mesh, and the actions played on the armature. What’s the best way to access both of those objects via python if the script is attached to one I the objects? (I’m sure there’s an easier way to explain that)

I know I can access by getting the object from the scene list, or by properties. But what’s the cleanest and most efficient way of doing this?


Just to make sure:

the mesh is a separate kind object type. I guess you are meaning a “mesh object” which is a game object with an assigned mesh.

What you want is pretty simple:

Inter-object logic brick connections.
The simplest method. You do not even need Python.
You can connect the logic bricks of any object with the corresponding logic bricks of another object (just select both objects ;))

connect an AND controller
-> with the action actuator of the armature
-> with the whatever actuator of the “collision object”

in Python you get the objects from the actuators:


Parent relationship:
Still a simple and flexible method.
You know your “collision object” is the parent of the armature.
That means the armature can get the reference to the “collision object” with:


the “collision object” has to search through it’s children:

for child in gameObject.children:
   if <however you can identify the aramature>:

Object search
The far most inflexible and most inefficient method is to search through the scenes.
Similar to above you need a method to identify the according objects (e.g. by name, by property …)

Just the answer I was looking for. Thank you so much Monster, you always give a very well thought out and elegant answer to peoples problems. I had a sneaky suspicion that the Object Search method would be the slowest.

Okay back to scripting :slight_smile: