bad physics with attached actors

Hello everyone, I’ve encountered a problem: I’m making a game with a modular weapon, it is possible to pick up a part (turn off collision and physics, attach to the player component), release it (turn on physics and collision, detach from the player) and put it on another part (enabling collision, detaching from the player and attaching to a part) so when attaching to a part (more precisely, a magazine to the receiver), a certain incident occurs; when release, the magazine does not allow the receiver to fall, or rather slows it down greatly, and even gives the effect of a paper airplane If you throw the receiver while running, I can’t install physics for the magazine because when you turn on physics, the actor is separated from the parents, that is, the magazine will simply detach and will not be part of the weapon. Has anyone encountered this and what can be done about it?

(I’ve used Google Translate, so feel free to answer in any lang)

here is video of that issue https://youtu.be/Hcj4hfYSfGU

generally with a weapon/mod collision would always be disabled and then if you want to ‘Eject’ it to the world only enable physics/collision then

strange that this only happens to gun mesh but others are working fine. maybe if you can share bp’s of your logic like attaching and detaching of weapon/attachments, that would help more to debug

im not sure that i get it, ill try disable collision anyway

theres way it should work:

every gun part can be damaged while attached to reciever, and every part should be physically touchable, when detaching it should simulate physics, im not sure difference between phys sim and collision, nvm ill try.

(post deleted by author)

it works, disabling collision makes some result but with that ive lost physical collision of parts, i think there is way to solve in copying collision model from part to reciever, is there any node for it?

Hey @The_KvaDRoniKuS

It might be that the magazine collision is clipping with the receiver?

(post deleted by author)

i thought that was, and it was, but in another way (wnen i release reciever with magazine them just fly away with speed of light, ive fix that by move socket)

here is main logic, set me (to set part on reciever), unsetme (to un set from), grab (to pick up or detach from and pickup), release (to release lol)




Hi, The issue you are having with the modular weapon system is probably due to the physics handling in Unreal Engine when attaching or detaching components. When you attach the magazine to the receiver, if I understand correctly, collision and physics behave strangely, causing unwanted effects like “paper airplane” behavior and when you throw the receiver the magazine activates physics and separates from the weapon, at least that’s what I understood from the video :slight_smile:
Now, I suggest, instead of enabling/disabling physics for individual parts, try using physics constraints to manage the relationship between the receiver and the magazine by creating a “PhysicsConstraint” actor between the receiver and the magazine and try to adjust the constraint to allow certain movements during the attachment (e.g. lock some rotation or position axes).
From this make sure that when the player releases the receiver or the magazine, the constraint can keep the two parts joined, still allowing realistic physics interactions (without the magazine detaching). (You may be thinking that in theory it is simple but then in practice it becomes a problem, however I guarantee you that if you google “PhysicsConstraint Unreal Engine” you will find something.)
Temporarily disable gravity for the magazine
If you need to ensure that the magazine stays attached to the receiver while it is being attached, you can temporarily disable gravity on the magazine:

When you attach the magazine to the receiver, disable gravity for the magazine (SetEnableGravity(false)).
When you release or detach it from the weapon, re-enable gravity on the magazine.
This will prevent the magazine from detaching prematurely when the receiver is thrown or handled with physics enabled.

For finer control over how objects, such as the magazine, behave during interactions, use a Physics Handle.

A Physics Handle allows you to grab and move the magazine while you are attaching it to the receiver.
When you want to release the magazine, release the physics handle and then re-enable gravity or physics on the magazine to restore normal behavior.

If the magazine still doesn’t behave as expected when attached to the receiver, try adjusting the physics properties, such as:

Make sure the mass of the magazine and the receiver is balanced. A magazine with too little mass may cause the “floating” effect if the receiver is too heavy.

Cheers

1 Like

you dont want any physics or physical collision for this, while attached otherwise it will mess with the parent actor.

you can use query only collision to respond to line traces if you want to damage a part.

when you eject, drop, throw the weapon you can enable physics then however you may want to offset it with SetActorLocation so it doesnt instantly collide with its parent actor which is what caused it to launch off

OK THANK U
for even guidline where to dig, ive fxcked up my whole brain while trying to make that constraints and now it works! here simple function to attach any gunpart to any another

(it takes socket transform from SKM, spawns constraint actor with theese transforms then it gets meshes, set transform of a part to socket, and set constrained components using meshes, in this way gun have good phys model and collision, doesnt fly away and doesnt fxck my brain anymore.)

1 Like