Unique object data

I recently discovered that unlike in Blender, while running in the BGE you can get away with having multiple objects named the same thing (i.e. those coming from an Add Object Actuator) which is a problem for me because I was using the name to tell the difference bewteen various objects (assuming it named them OBCube.001 and so on). I was wondering if anyone knew of some property of an object that is unique to it?

The names are equal because they are copies of the same object.
Rather than using object names, you can work with object references.


  • provides you with a list of object references, not with a list of names.

You can by object name (which is not how lists should work,) but if the object names are ambigous you get just one of them.

If you do that:

for obj in GameLogic.getCurrentScene().objects:
   #obj is the reference to an object
   print("my name is "+obj.name+" and my properties are named "+str(obj.getPropertyNames()) )

To identify an object with a special property you could do that:

def findObjectsByProp(propName):
 return [obj for obj in GameLogic.getCurrentScene().objects if propName in obj]

or all with the same name:

def findObjectsByName(name):
 return [obj for obj in GameLogic.getCurrentScene().objects if obj.name==name]

or if an properties value equals an given value:

def findObjectsByPropValue(name, value):
 return [obj for obj in GameLogic.getCurrentScene().objects if propName in obj and obj[propName] == value]

all functions return a list. If no object was found the list is empty len(…) == 0.

I str()'ed and printed the object references and all of the copies read OBCube, but I presume that if I were to use them as objects, they would access a particular cube and not all of them?

You can also use the id( object ) function if you need unique instance identifier.