I’m trying to attach a static mesh component (weapon) to my character’s skeletal mesh component’s socket and then allow it to be detached, re-attached, re-detached, etc…
The problem is I can’r re-attach it a second time. Here’s how it goes right now:
- Attach weapon for first time, it attaches to socket. Perfect.
- Detach weapon, it drops to the floor. Perfect.
- Try to attach it again. It stays on floor. Not perfect.
It works ok if I don’t set the Set Simulate Physics to TRUE when detaching the weapon. But, I don’t want the weapon to be floating in mid-air, I want it to drop to the floor.
Here’s the attach blueprint:
And, here’s the Detach blueprint script:
You need to setup a way to turn simulate physics off once you have completed the detach otherwise after the detach happens it will remain as simulating physics and won’t attach back to the socket normally. You may need to set it up as a BP so you can call a function on it to turn off simulate physics when you go to pick it up again.
The weapon is a BP. The attach/detach images above are from the weapon’s BP.
I set the simulate physics off right before I attach the weapon to my character. And I set it on right before I detach it from my character.
Is the mesh the root component in the weapon BP?
The Static Mesh comes after the DefaultSceneRoot:
Oh ok, I think maybe it is dropping away from the root when you simulate physics on the mesh and the root is staying where it was…I think the mesh is moving away from the SceneRoot basically… try testing it with the mesh as the root component.
The problem I’m having now is that each weapon I have is a child class of the main weapon BP, just with different meshes.
If I position one of the weapons correctly in the skeleton, it affects how ALL of the weapons are positioned.
How do I set the position of each weapon correctly? I can’t adjust each weapon’s mesh in the blueprint because they’re now the root.
At what point are you turning simulate physics off?
Right before I call AttachActorToComponent
Ok you need to move the root when you do that so try something like this with the weapon setup as it was originally so you don’t have to do a bunch of extra work with sockets/locations:
This should be inline with setting simulate physics to false…so what should happen is just as you turn off simulate physics the root should move to match the weapon mesh location and then it should snap back to the socket normally.
OK, I get it, thanks.
I could also set the Pitch/Yaw/Roll of the mesh. That would set it permanently, right?
Yeah until you set it again…something you could setup on begin play is the mesh transform and then when you move the root you could reset the mesh to its begin play transform.
OK, so to recap for anyone with this same problem…
- Make the Static Mesh the DefaultSceneRoot
I’ll play around with the different options for getting the mesh to fit correctly in the socket.
Thanks so much for your help, Black Phoenyx!