logic.getCurrentController().sensors['Collision'].hitMaterial does nothing?

My code is currently:

from bge import logic
Collisions = logic.getCurrentController().sensors['Collision']
print('"',logic.getCurrentController().sensors['Collision'].hitMaterial,'"')

but if you were to run this code it would output " ".

I want it to output the material, the face of the object collided, or the colour any one of these would work. Currently as suspected I’m attempting to print out the collided material(s) that is/are hit in the collision. I have checked the type already and yes it is a blank and empty string, this has left me very confused as I do not really understand what the problem is(perhaps just a bug in the bge?).

These aren’t likely of any consequence but my blender version is 2.78, and my setup is:

I’ve tried every adjustable setting there is for the collision sensor, and to no avail can I pythonically retrieve the desired material.

Any help would be greatly appreciated.

indeed hitMaterial does not work, in 2.79 either.

dir(Collision) will tell you the function is there but it just prints a blank space

The collision doesn’t work for me me also, until I switched the sensor option Invert on.

Edit 1:
Still doesn’t work with Python. Only with pure Logic Bricks for some reason.

Edit 2
Ok, work-arounds to detecting materials without material collision.

#Prints MA in-front of the material name to state that it's a material.
logic.getCurrentController().sensors["Collision"].hitObject.meshes[0].materials

(or)

logic.getCurrentController().sensors["Collision"].hitObject.color
1 Like

that isnt going to work with more than one material.

with upbge, construct bvh from a mesh could help. search through the three, get nearest index to collision point, look at material assigned to poly at index. but outright forget about it in vanilla.

1 Like

triangle mesh can return a poly proxy from a raycast

you can use collision + callback to get the hitpoint and raycast there and get the poly-proxy and use it to work out what material a object has.

1 Like

Totally forgot that you could do that, thanks for the reminder :+1:

that’s great for the upbge but we’re on the bge here. thank you for the advice.

I apologize for my absence, something came up.

oh right, i wasnt clear what you where working with. sorry.

2.78 has collision callbacks afaik. you should probably try what BPR suggested:

these both have the exact same problem, they only return 3 blank spaces.

are you by any chance referring to “logic.getCurrentController().sensors[‘Raycast’].hitNormal”
in order to approximate the material based on the objects hit location?
e.g. a polygon proximity check?
I suppose that could work but i feel it’d be slow and inefficient.

check the last option out on this *
https://docs.blender.org/api/blender_python_api_2_66_4/bge.types.KX_GameObject.html#bge.types.KX_GameObject.rayCast

ayCast( objto , objfrom , dist , prop , face , xray , poly )

get to know the poly option

what does it mean?