Is there a way to determine the Material Element Id that has been hit?

I am currently using LineTraceByChannel to select an object in my scene and change the material, some of these objects have multiple material elements, is it possible to retrieve the element id that is hit?

I can change it fine as long as I assign a pre determined index. I’ve tried to use the hit item directly into the element index (no result) and also tried putting the hit item into an integer variable before trying to attach it to the element index

I have also been looking for a way to do this; hope an answer comes up.

Architecture visualization, some assets have multiple materials on them.

Are you trying to just change the material on the object you’re hitting? What is the purpose?

i dont know if theres an id specifically… do you need that? or do you just need the exact name of the material that it hits on the object?

There is an element ID, that is what I need to retrieve. If I had a chair and the legs were element Id 0 and the seat was element Id 1,i want to determine which element I’d I hit with the line trace so I can change that material associated with that element ID.

Sorry, I don’t work with materials much.
I just tried this and I think i got the index number of the material my trace hit printed to screen.

You can do whatever you want with the index once you have it right… hopefully its what you need.

Thankyou for your reply I’ll try this tomorrow and see if it works for me.

I tried this, I kept getting the response 2, even if there was only 1 element id

Looks like this only works with set physical materials, not rendering materials. Phys Mat always returns “None” so it never matches and just runs through the all indices in the forloop. It does not seem like one can get the material element index out of the Break Hit Result node.

for the response 2, put a -1 between the number of materials and the last index…

its returning 1 material, when the true index is 0.

but as for the physical materials VS rendered ones…I dont know much about that really

good luck

first of all Break Hit Result from LineTrace and get FaceIndex , Hit Component.
then you need function Get Material from Collision Face Index

you can get from it value (and name) of hit material, then just check all materials with the same name.
In the end you get material index of this static mesh, that you can change in the future.

1 Like