How to get material by line trace

I want to get the material of the static mesh using line trace, because the static mesh hold more than one material. I set complex line trace by chaanel, but the FHitResult does not return a rendering matrial, so I want to use FHitResult.FaceIndx to get the triangle’s material. Is there any advice?

Here is a similar question. Hope you find your answer there!

Hey CppCode-

One solution you can use would be to use the FHitResult to get the component that was hit, then get that component’s material. Here is an example of how this would look: hit.GetComponent()->GetMaterial(0);

Cheers

Doug Wilson

Thank you. but the static mesh may have more than one materials(top face does not share a same material with left face), so I want to know the material of the face my line trace hit

Thanks.I read it, but seemed helpless.

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.

Nice answer, but why not just use “Section Index”? we could do GetMaterials[SectionIndex]