RigidConstraints aren't destroyed by :BreakJoints() and aren't returned from :GetJoints()

Reproduction Steps

1. Create a RigidConstraint between two parts.
2. Run :GetJoints() or :BreakJoints() on either part and observe that the RigidConstraint is ignored.

Expected Behavior

The RigidConstraint should be destroyed when :BreakJoints() is called, and should be returned from :GetJoints().

Actual Behavior

The RigidConstraint is not contained in the result from :GetJoints() and is not destroyed when :BreakJoints() is called.

Workaround

RigidConstraints must be explicitly searched for. If the RigidConstraint is not immediately present in a known part it is non-trivial to locate it.

Issue Area: Engine
Issue Type: Other
Impact: Moderate
Frequency: Constantly

4 Likes

This is a consequence of the class hierarchy - RigidConstraint inherits from Constraint, whereas the other rigid joints inherit from JointInstance.*

Here is the full behavior:

  • BreakJoints: It only works for WeldConstraint and JointInstances. It does not break Constraints.
  • GetJoints: Check again - it actually does return Constraints, JointInstances, and WeldConstraints. You can use it to implement BreakJoints-like behavior for constraints.

We can add a special case for BreakJoints to work with RigidConstraint, but it would break existing content and would add an odd corner to the API that you would have to think about.

For now, you can get the same or better behavior as BreakJoints with a few lines.

local function breakEverything(part: BasePart)
    for _, joint in part:GetJoints() do
        joint.Enabled = false
    end
end

This works with constraints.


* Except WeldConstraint, which is sort of out there on its own.

Hey, thank you! I figured that RigidConstraint would be treated the same as WeldConstraint since they’re both rigid, but I respect the decision to avoid adding more of these potentially difficult to account for edge cases. Thank you for the clarification that this is intentional behaviour, I will make sure to keep it in mind in the future!


I had tested GetJoints and I was for some reason unable to find RigidConstraints that way. I implemented some code that looked like this:

local function breakJoints(part: BasePart)
	for _, joint in ipairs(part:GetJoints()) do
		joint:Destroy()
	end
end

When I used this code, the RigidConstraints persisted, and after trying to print out part:GetJoints() I was consistently seeing an empty table, despite the existence of the RigidConstraint.

Perhaps I was simply misreading something, a bug or an oversight on my part is probably pretty likely, so I will make sure to go validate, and I will test in a more isolated environment. If RigidConstraint is not being returned from :GetJoints() I will make sure to submit a separate bug report for that that appropriately identifies that specific issue.

Again, thank you, I appreciate your response!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.