I can't figure out how to use the "AttachToComponent" node

Here’s basically what I’m trying to do: When the player pushes a certain button, the character will attach himself to whatever he’s standing on. Pushing the button again will detach.

But instead, when I push the button, the character teleports to some seemingly random location on the map. It could be very near, or it could be very, very far away from the component he was supposed to attach to. If I then try to move (with the analog stick), sometimes he teleports some more, and sometimes he then starts sliding very fast, and gets very far away from the component. I can’t see any pattern to it.

The “print string” node is displaying the correct component name, so that’s not the problem. I tried all the settings on the node for location rule, (keep world, keep relative, snap to target,) but none of them seem to make any difference and neither did any of the other options. There’s nothing else in the blueprint that could be interfering. I just don’t understand it. What am I doing wrong?

Did you tried to use “Keep Relative”?

Yeah, man I did. I tried all the location rules, each with and without “weld simulated bodies” checked, but nothing seems to make a difference.

So, how is this “AttachToComponent” node supposed to work, anyway? What happens when you use it?

I’m using it in the third person template. I want the player to be able to attach himself to the walls and floors, so that strong winds can no longer push him, or if the walls are moving, he’ll move along with them.

I already have a wall and ledge grab mechanic in my game well and working, as well as the ability to move around while climbing. But it doesn’t work if the walls are moving, in which case the character won’t stay “attached” to the wall/ledge.

But for starters, I was just seeing what would happen if I attached him to the ground, and it’s nothing like I expected.

I think in your case it is better to get relative location to walls and add it to player location.
Because if you set player location from climbing code, it may have conflicts with attachment.

Maybe it will work if you use attach actor to actor, and in climbing code set only relative location to wall…

I’ve add movable static mesh actor into map and create this setup:

It slowly moves and when I step on it it looks like my character successfully attached.

But my character moves x2 faster than platform itself. I think its because engine already attached actor to moving platform by some native logic, and I make additional attachment.

Also my character teleported somewhere if I use “Keep Relative” for location.

Getting closer… :stuck_out_tongue: I copied your blueprint above, and noticed the same things you mentioned, like sliding twice as fast when standing on it. But for some reason, if I try to move while on the ground, then he starts teleporting again. Does this happen to you? If I move while falling or flying it works just fine, no teleporting then. If I hold still on the ground he doesn’t teleport, it only happens while moving.

Although I’d like a fix for this, I could probably work around it and just forget about attaching him on ground. It’s more important that I get him attached while in climbing mode. So I added on to the blueprint:

Now we check to see if the player is flying before attaching, (“flying” is the mode I use for the climbing code.) and if he ever stops flying, we detach. So it works pretty good like this, but another problem has arisen: For some reason the collision only works while the player is moving. But don’t worry, it has nothing to do with the attaching. No hit events at all will work. Doesn’t matter whether I’m flying or standing, the moving block will just phase right through the player character if he’s holding still, and I don’t know why.

If you have any ideas, let me know. (Sorry if it’s something obvious.) Until then, I will be scrambling the internet for answers some more, lol. If we can’t find the answer, I might be able to use a trace or something to detect the moving block, but that will be more tricky to do.

Have a nice day!

But for some reason, if I try to move while on the ground, then he starts teleporting again.

No, i can walk normally.

For some reason the collision only works while the player is moving.

Yep, it is normal behavior for flying character. Maybe this is not good solution for you, but in one project I’ve fixed it by adding capsule trace function which called if character movement input axes == 0.
It makes trace in character location +/- 1unit, and if something was hit - it applies impulse to character to push him in opposite direction.

Ah, that’s really good to know! : D

Hearing that you could walk normally confirmed that something was wrong with my game. and with that, I finally tracked down what the problem was:

Rather than using the default “orient rotation to movement” I instead made my own way of rotating the character to the last direction pushed, and I used a “move component to” node to do it. The node set the actors location to the same location it was already in, and this never interfered with movement until now… So I removed that line of code, and that stopped the teleporting problem.

I still can’t believe how glitchy this made things. I thought by setting the location to the current location, it would just ignore changing location altogether. But apparently not. :confused:

Now as for that capsule trace you mentioned, I think I could make this work for me!

Thanks for your help, red. (This is the second post you’ve helped me on, btw.) x)