Could someone show me some example code of Ray Tracing A Skeletal Mesh and returning the Actor. I am trying to look at a Skeletal Mesh Rifle on the ground and then attach it to my character but it is having trouble returning the actor from the ray trace.
If your skeletal mesh rifle is a pickup in the level, it is more efficient to use a static mesh version that has no bones and uses simple geometry for collision, this is just for a visual pickup representation that could also optionally have physics.
if you really want to use a skeletal mesh for your pickup, I can still recommend using a box collision primitive in the actor class to assist with collision detection, much like how the character class works with a capsule component. This would give you benefits of #1 without requiring you to re-import the asset as a static mesh.
As a final method, ensure your skeletal mesh rifle has a proper physics asset, this is what gets used for component level traces
It’s not that easy / efficient to do a trace straight against the physics asset without incorporating simple primitive collision of #1 or #2
**Summary**
Your fundamental weapon pickup actor needs to be adjusted before a code sample would become relevant, and once you have some primitive collision for your weapon pickup its just a simple line trace from your character / screen center.
**World.h**
```
/**
* Trace a ray against the world using a specific channel and return the first blocking hit
* @param OutHit First blocking hit found
* @param Start Start location of the ray
* @param End End location of the ray
* @param TraceChannel The 'channel' that this ray is in, used to determine which components to hit
* @param Params Additional parameters used for the trace
* @param ResponseParam ResponseContainer to be used for this trace
* @return TRUE if a blocking hit is found
*/
bool LineTraceSingle(struct FHitResult& OutHit,const FVector& Start,const FVector& End,ECollisionChannel TraceChannel,const struct FCollisionQueryParams& Params, const struct FCollisionResponseParams& ResponseParam = FCollisionResponseParams::DefaultResponseParam) const;
```
Enjoy!
:)
Rama
Regarding 2), you can also duplicate your skeletal mesh and create a new physics asset in which you set up only a single box volume that covers the whole mesh - this should register line traces. Then, in your FHitResult, you should use the function GetActor() instead of the Actor property.
LineTraceSingle() - it’s been deprecated, so we should now rather use LineTraceSingleByObjectType().