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