is it possible to copy a property from a collision object?

just as the tittle says, i wanted to know if there was a way to copy a property of an object that collides with my character. the only method i was able to find via the search was one for 2.4, and it doesn’t work (sadly)

Anyway, basically, i wanted to know how to get the id of the collision object, or if you even still can (again, the post that i found had a way to do it, but it nolonger works), then get a property from it, and copy that property to the controller (i already know how to copy a property, and how to get the controller, but it’s getting the property from the other object, as well as the other object in the first place that i am having trouble with)

I think this should work:

property_names = ["prop", "score", "life", "blah"] # Those you want to copy, that exist on gobj_copyfrom

for prop_name in property_names:
    gobj_copyto[prop_name] = gobj_copyfrom[prop_name]

er, that still doesn’t exactly tell me how to get the collision objects data to copy the properties from, i guess i didn’t explain myself very well. i’ll edit my first post so that it explains a bit more. Sorry about that.

Sounds like you need to upgrade to 2.49 API

With a python controller:

#--- BGE callables
def copyProperty(cont):
  if not allPositive(cont):

  hitObjectSensor = findHitObject(cont)
  if hitObjectSensor is None:

  hitObject = hitObjectSensor.hitObject
  if hitObject is None:

  collider = cont.owner
  copySensorProperty(collider, hitObject)

#--- Internals
def copySensorProperty(destination, sourceSensor):
  '''Copies the property named by the sensor'''
  propertyName = sourceSensor.propName
  source = sourceSensor.hitObject
  destination[propertyName] = source

def getHitObjectSensor(cont):
  for sensor in cont.sensors:
      return sensor
    except AttributeError:

def allPositive(cont):
  for sensor in cont.sensors:
    if not sensor.positive:
      return False
  return True


Python Module: collider.copyProperty

You forgot to mention how you want to decide which property to copy. The above code copies the property set up in the sensor.
If you want another method, modify the function copySensorProperty() or add another one.

For what do you need the Id? it is pretty useless except you want to manually compare two objects.

Which one?

Controllers do not have properties. I guess you mean the controllers owner = game object.

As shown above:

  • get the reference of the hit object from the sensor
  • get the reference of the controller’s owner (or the sensor’s owner)
  • identify the property names you are looking for
  • identify the property names you want to receive the value
  • read the values from the source object
  • write the values to the destination object

You mean downgrade. i did upgrade, that’s the problem, the 2.49 one no longer works, i’m now using 2.62, which is why it doesn’t work anymore. T_T

Going based off of your code, i’m now positive that the old way actually does still work, which means that i no longer know what is wrong. i think the issue is that the text object is just not copying the new property from the character. (it copies the property i want from the object it hits, then the text object, which is on a new scene is supposed to copy it from the character using a normal logic brick, but it’s just not working.

thanks for the help, i finally found out what was wrong with my method. apparently, you can’t send properties from scene to scene like you used to be able to, (That, or you never could do it before), so i had to make a script for that, and it worked by the way :slight_smile:

anyway, thanks everyone for your help :smiley:

Good that it works.

I meant upgrade. You used the API from before 2.49 as you mentioned in your top post. 2.49 works with both API’s and shows deprecation warnings to help upgrading the code. The 2.49 API is fully compatible with 2.5+ (except Mathutils which does not exist anymore).

With 2.5 you need to use Python 3 syntax (e.g. print -> print () ).