Proper Collision Setup for a Weapon Pickup
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
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.
* 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;