AttributeError: ‘KX_TouchSensor’ object has no attribute ‘objectHitList’
It’s late for me, so maybe I’m too tired for this, but why is this happening?
Surely a KX_TouchSensor has the objectHitList attribute…?
Surely a KX_TouchSensor that just triggered this very controller has collision objects…?
-All spelling and names are correct.- (Edit: NO they were not! See below)
The Sensor is set to defaults, just as it is when it comes out of the “add sensor” list.
The Controller is set to “module.” It calls “Utilities.collisions” from “Utilities.py.” Other functions in this script work.
It doesn’t start spewing this error until the moment a collision occurs, and for every collision thereafter.
Using the sensors status to decide the code execution path doesn’t seem to help. The sensor triggers the controller, and reports positive (all because of a collision), but errors when a read of the objectHitList is attempted.
Thanks for the assist.
Edit: Got it sorted.
I AM too tired for this.
…
It’s named “hitObjectList” NOT “objectHitList” (Yeah, the word order certainly matters.)
…
Yes, indeed, I AM aware of the BGE API docs. Point of fact I was using that to assert that objectHitList was an atrib of KX_TouchSensor. (See here.) Though I could complain about the BGE API docs lack of complete descriptions or examples, it is still my goto reference for scripting the BGE.
My problem was reading comprehension. I guess I need to wash my glasses.
Like I said, the word order was wrong. So I kept reading that KX_TouchSensor had the objectHitList attribute, and I kept getting the error like it didn’t… because it doesn’t… it’s named hitObjectList.
OH! I know why I had it backwards now… It’s in one of the blender template scripts!?
Open Blender.
Open text editor.
Click Templates > Python > Gamelogic
… near the bottom, in triple-double quotes, you’ll see the same INCORRECT reference to objectHitList. I’ll paste here.
# Example where collision objects are checked for their properties
# adding to our objects "life" property
"""
actu_collide = cont.sensors["collision_sens"]
for ob in actu_collide.objectHitList:
# Check to see the object has this property
if "life" in ob:
own["life"] += ob["life"]
ob["life"] = 0
print(own["life"])
"""
***Interesting…
Was objectHitList the attributes name in BGE some thousand years ago or something?