Working with Instances or Sprites

So I have a game with a map and a camera in the 3rd person view. There are cities to click on and terrain features. The idea is to set it up so you can march units of many guys from the city to fight the other cities and conquer the map.

I have characters that I spawn at the cities, they have clothing which are separate objects parented to the characters. The characters are not hundreds of individual meshes, but instances of only a few objects. I have problems interacting with my instances. I cannot call them with scene.objects[this particular instance], because I don’t know what this particular instance is. The characters are created as such: bones for animation with a child “body” which has a child “pants”. The logic is on the bones.

I would like my guys pants, which are parented to my buys body which is parented to my guys bones to change color according to my guys “faction” property which is found on the bones. How should I approach this?

I’m thinking I could have the “bones” tell the “pants” what faction it is and have the “pants” then set the color accordingly, but I don’t know how to figure out how to get the “pants” parent to ask or to find out how to get the child to reply. If I had individual objects, I could do this with logic bricks and a brief script, but I don’t know how to do it with all these instances.

I could just do it at spawn, which seems logical. My spawn code currently looks like this(abridged), but I don’t know how to access my guys pants.

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
owner = cont.owner
query = “cityplane”

figures out which faction the city is.

faction = scene.objects[cityplane][“faction”]

#thanks to cotak for the last_added idea helped me
#find the instance added so I could set the faction to

the city faction property.

for x in range(0,30):
last_added = scene.addObject(“myguy”,cityplane,0)
last_added[“faction”] = faction
last_added[“selected”] = True

Or am I approaching this the wrong way and there is a better way?

And is my guy set up right?
bones with logic and properties(parent of body, grandparent of pants)
body(child of bones, parent of pants)
pants(child of body)

Should I set him up differently?
And I’m sorry if this is excessively long. I’m trying to give all the info needed to answer the questions and I’m not sure exactly what would be useful.

factionColors = {"Boyscouts":[0,0,1,1], "Douches":[1,0,0,1]}

pants = last_added.childrenRecursive[name_of_child_object]
pants.color = factions[ last_added["faction"] ]

The name of the child object will always be equal to what you originally set it to unless manually changed, ie object.name = value.

Thanks! I did get this to work.