Physical Material From Line Trace best practice

Hi guys,

I am performing a line trace in CPP, and getting physical materials from the line trace based on what material it hit.

I can get the physical material from the hit results fine, but am wondering what the best practice is for determining which physical material was hit:
For example, I want to check whether HeadMaterial, TorsoMaterial or LegMaterial was hit - what would be the best way to go about checking the physical material? I know that I can test for FStrings using PhysMaterial.Get()->GetFName().ToString() and just use switch-case to compare which material was hit, but is there a better way that is preferable?

Thank you

Hey DanZeDev,

doing string comparison would be my last solution.

I’m not an expert, but I would create 3 UMaterialInterface* UPROPERTIES that I would assign the materials I’d test against to. You could do that either by blueprinting your class and assigning the materials in the class defaults or using the ConstructorHelpers::FObjectFinder if you want to use C++. Now it would be a simple if…elseif…else testing against the returned material.

1 Like

Hi pladux,

Thank you, this sounds like a much more elegant solution - string comparisons always feel disgusting, so this is much preferred.

You’re welcome. I didn’t tried that out. I’d be happy to know if that worked out. Please let me know.

It worked out very well, thank you - sorry for the delay, had to iron out some other issues first

1 Like