AttachToActor not working. Any ideas?

I got character movement done and decided to move on to some form of weapon pickup system.
I imported a friend of mines gun he made in blender after converting it to fbx, and at first i was attempting to setup the blueprint scripting on the gun, and that failed miserably. Then i had the idea of doing it this way (image below), and at first, it worked halfway. It was actually detecting anything set to block the “gunpickup” channel, and it was able to accurately display when i pressed e on the gun as opposed to any other item not labelled to block the trace channel “gunpickup”.However, it was not actually attaching to the specified grabpoint or actor. I tried every possible combination of attachtoactor, attachtocomponent, not specifying a socket name, etc. I did seemingly randomly get errors saying my grabpoint was not static while the item i was attempting to attach to was (not the case at all if it was referring to the gun, i was spamming e as i watched it fall to the ground.)
Ive been tinkering with it for a little over 2 hours now and its just worse. Now its not even displaying the “justbeforeattach” even when pressing e (my inputaction for equip/interact) on ANY object labeled with gunpickup or not, let alone actually connecting them

Ive tried with just about any combo possible. Yes, the socket name is correct, yes ive been setting the location and rotation rule to snap to target every time, yes ive swapped around the target and parent actor a multitude of times each try. As said above, now its not even detecting the gunpickup item when i press E, seeing as its not printing justbeforeattach.
Could someone please tell me what im doing wrong and point me in the right direction?

Its all 1 staticmeshcomponent inside of a blueprint.

Where can i find that option?
Im not seeing any playercontroller in my character BP or world outliner object list.
Apologies, new to UE4.

Could you show the collision settings of the object you’re trying to pick up?

Hey there. Couple of things to offer that might help out (I’m assuming this is an FPS):

  • Instead
    of tracing for what’s under the
    cursor, do a Line Trace from the
    Camera Forward Vector. Call a Get
    Player Camera Manager function and
    pull Get World Location and a Get
    Forward Vector functions from it, use
    the World Location one for the Start
    Point of the Trace and multiply the
    Forward Vector one by a float (say
    200 units), then feed the result to
    the End Point of the Trace. Imagine this as drawing a line 200cm out straight forward from the camera’s view.
  • Secondly, use an Attach to Component
    node where the component should be
    the Static/Skeletal Mesh of your
    CharacterBP, not just the BP/Actor itself, this should make the
    bone/socket Name you’ve typed in
    actually work.

Let me know if anything, cheers.

Are the Click Events Enabled in the player controller?
edit: also make sure the static mesh has collision in the first place. If you double click it and show collision, you should see a green wireframe.

The rest of your setup seems more than fine to me.

What’s the point of this? The issue is that the trace is not detected…

No need to be apologetic. To be honest I strongly believe your mesh has no collision. Could you quickly replace it with the 1M_Cube that comes with the engine - and see if it works.

Is the Input actually firing? Can you print something off it without a branch?

Ah, it’s starting to make sense. If the mesh is simulating physics, you may need to disable it just before attaching, otherwise the mesh will be still driven by physics.

Cast the Hit Actor to the mp7 object, get the static mesh and Set Simulate Physics {F} just before Attaching to Actor.

Yes, i will do that. 1 second please.

The input is firing. Just plopped the new cube in there and its giving me both justbeforeattach and attachattempted.
Not actually attaching it, and it is perhaps a little finnicky about my camera angle, but it is working as far as going through the line of code, atleast.
Put a collider on the mp7 and still no luck. I would say interaction distance as the mp7 does fall on the ground where its at my feet and i cant crouch, but ive not set any interaction distance.
Also, the mp7 still does have collision when it comes to physics. If i step on it i can actually push it around.

Edit: I stopped the simulation and am now getting the following errors when attempting to interact with the gun: Invalid simulate options: body (long line of text specifying tis the mp7) is set to simulate physics but collision enabled is incompatible

Yeah, the trace seems off.
Still useful information though, will make sure to keep those 2 things in mind!

Also! Lemme guess, the physics object - the mesh is not the root there, right? This will cause a lot of headaches with attachments since the simulated mesh is already attached to the root. And in this very case it does not even matter if you enable / disable simulation run-time.

The easiest solution is to make the static mesh the root. Otherwise you’ll need to manually deal with component attachments.

I’ll leave this here because it’s a gotchya! When trying to attach physics objects directly to actors, do ensure that the mesh is the Root Component:


Also, make sure to Weld Simulated Bodies{T}:

Image from Gyazo

Here’s what I meant but it’s not necessary providing the mesh is the root of the object:

Do check my answer below and do tell if things have improved.

That should work well; another solution is to show a pickup icon on keypress - think Diablo, hold alt and show item labels on the ground - especially usefully for small objects stuck in nooks and crannies.

But that’s more of a design choice. Having a slightly larger sphere collision dedicated only to user interaction could do the trick.

Good luck with the rest!

edit: in case the Get Hit Under Cursor does not deliver, do consider adapting @duderseb’s tracing suggestion. It, kind of, depends how the gameplay looks like.

If you ever tried to pick up something from a shelf that’s above the camera, tracing without channels is not fun at all!

That makes more sense.
Though i am a little bit confused, would i have to then go into the mp7 and set up some script there or would this be entirely possible within the character scripts?

It has a fair bit.
Now the system works and teleports the object to my body, and although in the wrong rotation/place, that can be changed.

My one current problem is with this system ive set up, it seems very, VERY picky as far as smaller objects such as the mp7 go. I decided id try putting a much bigger collision box set to only collide with the “gunpickup” physics, hoping to give it a little bit of a pickup radius, if you will.
Its still rather picky, though. Trying to figure out why.

Alrighty. Spent the last 30 minutes or so experimenting. Used @duderseb 's suggeusted method and now its perfect with the hit detection.
The only problem i have is im not understanding how to properly define my staticmesh component (named GrabPoint) as the parent of the target.
If i define my character, it works perfectly, except for the fact that the gun is in the middle of my character rather than the grabpoint. Ive tried attachtoactor, attachtocomponent, etc and i still cant get the game to properly connect the target to GrabPoint. Ive tried getting my character and then looking at the child items and trying to refer to Grabpoint, ive tried just getting a variable for the grabpoint and setting it that.

I dont understand if im just not seeing how to refer to a child static mesh object, or something in this script is incompatible and im just not recieving a warning/error message. Besides that, the system is all set, though.