I would like to get which element index (or, which material) was hit on a line trace test. From what I’ve seen this is currently not supported by the engine.
I’m currently digging into engine source to see what I could change to support this, but apparently only the physical material is saved in physx (which is what does the traces).
Any help on retrieving this information (hit material or element index)?
Epic must have a way to do this, because think about it
if you have a skeletal mesh with multiple material indicies, and you drag a material directly onto a certain part of the skeletal mesh, the material is applied to just that index!
Maybe look at where that is happening to get more info?
Take a look at FCollisionQueryParams. There is a flag called bReturnPhysicalMaterial which defaults to false. In some places in code we set this to true, and you should be able to then get it directly from the FHitResult.
As Rama & Ixiguis hinted, take a look at the “HActor” hit proxy code - that has a MaterialIndex which gets set e.g. in FSkeletalMeshSceneProxy::CreateHitProxies.
However a lot of that code seems to be editor-only, bear that in mind depending on what you’re trying to do. I think maybe HitProxies might not be fast enough to use in-game, because they involve re-rendering the scene to generate the hit proxy map (see FViewport::GetRawHitProxyData()).
why not just break the “hit result” of the line check, get the “hit actor” or component maybe and “Cast to StaticMesh Component” then you can get material on that. Or you can get number of materials and do a loop to get each material.
This does not seem to work when a mesh is composed of only one component, but has multiple rendering materials—at least for grabbing the one specific hit material.
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.