Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.alt text

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.

alt text

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.


Product Version: UE 4.18
more ▼

asked Feb 03 '18 at 07:46 PM in C++ Programming

avatar image

413 17 15 31

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Feb 04 '18 at 01:03 AM

avatar image

176 1 3 3

avatar image erik321123 Feb 04 '18 at 01:08 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question