# Line trace: how to get hit material?

**URL:** <https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646>\
**Category:** Rendering\
**Tags:** Trace, unreal-engine, question\
**Created:** [October 8, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646 "2014-10-08T22:23:53Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ixiguis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ixiguis](https://forums.unrealengine.com/u/Ixiguis)\
**Post date:** [October 8, 2014, 10:23pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/1 "2014-10-08T22:23:53Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [October 9, 2014, 8:35am UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/2 "2014-10-09T08:35:27Z")

</div>

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?

Let me know!

---

<div class="post-metadata">

**Author:** ![Ixiguis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ixiguis](https://forums.unrealengine.com/u/Ixiguis)\
**Post date:** [October 9, 2014, 10:02am UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/3 "2014-10-09T10:02:15Z")

</div>

Yeah, drag and dropping from the content browser onto a static mesh works too. Any idea where that could be implemented?

---

<div class="post-metadata">

**Author:** ![Ixiguis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ixiguis](https://forums.unrealengine.com/u/Ixiguis)\
**Post date:** [October 9, 2014, 10:27am UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/4 "2014-10-09T10:27:45Z")

</div>

Apparently it starts in LevelEditorViewport.cpp FLevelEditorViewportClient::DropObjectsAtCoordinates()…

---

<div class="post-metadata">

**Author:** ![\_Epic\_Ori\_Cohen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_Epic\_Ori\_Cohen](https://forums.unrealengine.com/u/_Epic_Ori_Cohen)\
**Post date:** [October 9, 2014, 1:23pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/5 "2014-10-09T13:23:50Z")

</div>

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.

Hope that helps

---

<div class="post-metadata">

**Author:** ![Ixiguis](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ixiguis](https://forums.unrealengine.com/u/Ixiguis)\
**Post date:** [October 9, 2014, 2:43pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/6 "2014-10-09T14:43:06Z")

</div>

Hi Ori,

Thanks for the answer, but that’s for getting the physical material. I want to get the (rendering) material, or the mesh’s element index.

---

<div class="post-metadata">

**Author:** ![DarknesZ](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/darknesz/32/610815_2.png) [@DarknesZ](https://forums.unrealengine.com/u/DarknesZ)\
**Post date:** [June 30, 2015, 2:13pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/7 "2015-06-30T14:13:06Z")

</div>

i’m looking for the same thing…

---

<div class="post-metadata">

**Author:** ![Bennicus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bennicus](https://forums.unrealengine.com/u/Bennicus)\
**Post date:** [June 30, 2015, 4:17pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/8 "2015-06-30T16:17:16Z")

</div>

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()).

---

<div class="post-metadata">

**Author:** ![RyanB](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanB](https://forums.unrealengine.com/u/RyanB)\
**Post date:** [July 1, 2015, 7:15pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/9 "2015-07-01T19:15:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![LuxFlux\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@LuxFlux\_1](https://forums.unrealengine.com/u/LuxFlux_1)\
**Post date:** [July 22, 2015, 5:35pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/10 "2015-07-22T17:35:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![6r0m](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/6r0m/32/1194563_2.png) [@6r0m](https://forums.unrealengine.com/u/6r0m)\
**Post date:** [March 14, 2018, 8:33am UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/11 "2018-03-14T08:33:13Z")

</div>

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

 ![233733-faceindexmat.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/4/c94aabaa40914b3fb41572e353847e67e02f180d.jpeg)

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.

---

<div class="post-metadata">

**Author:** ![Anik.13](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anik.13](https://forums.unrealengine.com/u/Anik.13)\
**Post date:** [March 25, 2024, 6:23am UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/12 "2024-03-25T06:23:53Z")

</div>

Hi, Can You please Share the whole blueprint. Actually I am new to Unreal Engine 5.3. And I have to do this Task.

---

<div class="post-metadata">

**Author:** ![anticlockworld](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anticlockworld](https://forums.unrealengine.com/u/anticlockworld)\
**Post date:** [December 9, 2024, 1:16pm UTC](https://forums.unrealengine.com/t/line-trace-how-to-get-hit-material/295646/14 "2024-12-09T13:16:41Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/d/2/ed28ae53cae47b46881a564d18c1e4f309e13d74.png)  
you need to use "trace complex "
