How to get name of UPhysicalMaterial (From FHitResult)

So I am trying to get a name of a physical material, so I can use it for material penetration en deflection for my projectiles. I have a FHitResult that contains a physMat (TWeakObjectPtr). It has the member Get() that returns a UPhysicalMaterial*. Which inherits from UObject.

229396-uphysmatdocs.png

But I can’t call UObject’s GetFName() on it. I also can’t cast my weakpointer or physmat to UObject to then get the name, since that will give me a compiler error.

None of this works

How do I get the FName of a physical material. In BP it is just GetObjectName.

Any help would be appreciated.

Hi there,

By the looks of it you are trying to use the physics material name to get a row from a data table, yes?
If so, I just did a test with a simple line trace and was able to get it to compile, and also return the found row, using the same code as in your image. However, in yours it seems the (presumably) hit result variable you declared may be the problem. Is your hit result a pointer by chance? If so, you should use the → operator to access the PhysMaterial variable, and then continue with the code you had. I tested that case as well, and had similar success. Hope that helps!

Here is my code. And, I’m using 4.18 by the way

// .cpp

// new hit result for some collision test (line trace, overlap, etc)
FHitResult NewHit;

// function using NewHit (again, line trace/overlap event, etc)

// Get row from data table based on the hit phys mat
const auto* Row = MyDataTable->FindRow<FMyStruct>(NewHit.PhysMaterial.Get()->GetFName(), "SomeContext");

// do something with Row

You’d fill in the blanks above with your own code of course.

Well this was stupid of me, I tried all of these combinations except .Get()->GetFName() with and without the physicalMaterial header… Thanks for your time