Get Object of Near Sensor?

I am creating the homing attack for my Sonic game, and I have setup like this:

Near (prop: enemy) ------- [python] -------- (steering)

The python script basically says this:


if near.positive:
        steering target = object that activated near
        cont.activate(attack)

The only problem with this is that I don’t know how to get the name of the object that activated the near sensor. Does anyone know how to do this?

It should just be near.hitObject to get the name shouldn’t it?

As scuba111223 say, the near sensor have a attribute, the “hitObject” returns a KX_GameObject of the object that activate the sensor, so you can use it:


if near.hitObject:
    object = near.hitObject

    #Example
    object.setParent("other_object") #You can use directly a KX_GameObject

    cont.activate("attack") #the activate function also accept a string.


Yeah, that worked. Thanks!

Be aware, the near sensor detects multiple objects (hitObjectList).