I’m trying to get information about the hit object’s physics material out of a LineTraceSingleByObjectType() trace.
The object definitely has a physics material assigned to it, and I’ve assured that this object is being hit by the raytrace, but in the FHitResult the physics material reference is invalid. (myHitResult.PhysMaterial.IsValid() is false)
I am able to reproduce this in a brand new project. Also, this only fails when performing raytraces in C++. In blueprints they work fine and return the correct Physics materials.
How can I get the physics material out of the ray trace?
I am able to reproduce this issue in a brand new project. If I use line traces through blueprints, the hit result in the blueprint has a valid physics material, but not when I perform line traces in c++.
Move the red cube towards and away from the cylinder and watch the output log. I’m performing a line trace of length 250 form the center of the red cube towards the cylinder. You can see in my C++ code class “MyActor::tick()” where I’m printing the messages.
I apologize for the delay. Since you’ve been able to reproduce the issue in a clean project, could you zip up that project and provide it? I have also confirmed that it works in blueprints.
I have been able to reproduce your issue, and have entered a bug report (UE-28640). Thank you for providing the test project. I will provide updates on this issue as they become available.
Have you made sure to set the bReturnPhysicalMaterial flag on the FCollisionQueryParams passed to the function? This defaults to true for BP traces, but is left to the caller for C++ users, as it is considered a slightly more advanced API.