Change multiple hing Joints with a single script?

It seems you can’t use

HingeJoint hinge = GetComponentInChildren<HingeJoint>(); 

and then use

foreach (HingeJoint joint in hinge) 

to effect all hinges nested under a parent object as HingeJoint doesn’t contain a public instance definition for GetEnumerator. So how can an Enumerator or list be made to solve this?

Say you have a chain connected to the floor and ceiling and you want it to move a little so you set limits.min and max ( but then you want the chain to break and change all the joints limits.min and max with a single script.
Or you have a double door and you want to lock it and then unlock it by changing the joints limits for both doors rather then each one individually. How would you go about making the script capable of using GetComponentInChildren? Or is there a better way I’m not thinking of?


I tried the HingeJoint hinges array with no luck and now even just trying to swap single joints at a time calling the functions below with a trigger event isn’t working?

using UnityEngine;

public class HingLockControl : MonoBehaviour
    public bool locked = true;
    public float lockedMinLimit = 0;
    public float lockedMaxLimit = 0;
    public float lockedBounciness = 0;
    public float lockedBounceMinVelocity = 0;

    public float unlockedMinLimit = -90;
    public float unlockedMaxLimit = 90;
    public float unlockedBounciness = 0;
    public float unlockedBounceMinVelocity = 0;

    HingeJoint hinge;
    JointLimits limits;

    void Start()
        hinge = GetComponent<HingeJoint>();
        limits = hinge.limits;
        hinge.limits = limits;
        hinge.useLimits = true;

        if (locked)

    public void SetLockedHingeLeeway()
        locked = true;
        // Set the hinge limits when locked.
        limits.min = lockedMinLimit;
        limits.bounciness = lockedBounciness;
        limits.bounceMinVelocity = lockedBounceMinVelocity;

    public void SetUnLockedHingeLeeway()
        locked = false;
        // Set the hinge limits when unlocked.
        limits.min = unlockedMinLimit;
        limits.bounciness = unlockedBounciness;
        limits.bounceMinVelocity = unlockedBounceMinVelocity;
        limits.max = unlockedMaxLimit;

In your case hinge is not an array.
This would work:

HingeJoint[] hinges = GetComponentsInChildren<HingeJoint>(); 

Note the added ‘s’ in GetComponentsInChildren
You can then use the foreach loop.

I would do it like this:

foreach (Transform child in transform) {
      if(child != transform) {
            HingeJoint hinge = child.GetComponent<HingeJoint>();
            // Do stuff with hinge here