Unity-Technologies/UnityCsReference · error · ArgumentNullException

One or more transforms are null

Error message

One or more transforms are null

What it means

Thrown by TransformUtils.SetConstrainProportions(Transform[]) when any element of the transforms array is null. The proportional-scaling feature needs valid Transform references for all targets.

Source

Thrown at Editor/Mono/Inspector/TransformUtils.cs:43

            return GetConstrainProportions(new []{transform});
        }

        public static bool GetConstrainProportions(Transform[] transforms)
        {
            return Selection.DoAllGOsHaveConstrainProportionsEnabled(transforms);
        }

        public static void SetConstrainProportions(Transform transform, bool enabled)
        {
            SetConstrainProportions(new[] { transform }, enabled);
        }

        public static void SetConstrainProportions(Transform[] transforms, bool enabled)
        {
            foreach (var t in transforms)
            {
                if (t == null)
                    throw new ArgumentNullException("transform", "One or more transforms are null");
            }

            ConstrainProportionsTransformScale.SetConstrainProportions(transforms, enabled);
        }
    }
}

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Filter nulls out of the transforms array before calling SetConstrainProportions.
  2. Use the single-Transform overload only for confirmed non-null transforms.
  3. Re-query transforms fresh to avoid stale null references.

Example fix

// before
TransformUtils.SetConstrainProportions(transforms, true);

// after
var valid = transforms.Where(t => t != null).ToArray();
if (valid.Length > 0)
    TransformUtils.SetConstrainProportions(valid, true);
Defensive patterns

Strategy: validation

Validate before calling

bool ok = transforms != null && transforms.All(t => t != null);

Type guard

static Transform[] FilterTransforms(Transform[] ts) =>
    ts?.Where(t => t != null).ToArray() ?? Array.Empty<Transform>();

Prevention

When it happens

Trigger: Calling SetConstrainProportions with an array containing a null Transform, e.g. from GetComponentsInChildren where some children are null, or a selection set with a destroyed transform.

Common situations: Multi-object transform editing where one selected object was destroyed mid-operation. Arrays built from LINQ that include nulls. Scripts caching transforms that later became null.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/02104e7038348266. Report an issue: GitHub.