stride3d/stride · error · ArgumentException

Vector component 'Z' is invalid, only 'X' and 'Y' are…

Error message

Vector component 'Z' is invalid, only 'X' and 'Y' are supported.

What it means

Vector2ComponentCurveViewModel edits one component of a Vector2 compute animation curve. Its constructor throws ArgumentException when given VectorComponent.Z, because a Vector2 has no Z channel to edit.

Solutions

  1. Pass only VectorComponent.X or VectorComponent.Y
  2. Make the curve factory dimension-aware (two components for Vector2)
  3. Remove stale Z entries from component/channel descriptors
  4. Catch ArgumentException and skip invalid component curves

Example fix

// before
new Vector2ComponentCurveViewModel(editor, parent, curve2D, VectorComponent.Z);
// after
new Vector2ComponentCurveViewModel(editor, parent, curve2D, VectorComponent.Y);
Defensive patterns

Strategy: validation

Validate before calling

if (component is VectorComponent.Z or VectorComponent.W) return null;
var curveVm = new Vector2ComponentCurveViewModel(editor, parent, curve, component);

Type guard

bool IsValidVector2Component(VectorComponent c) => c is VectorComponent.X or VectorComponent.Y;

Try / catch

try { vm = new Vector2ComponentCurveViewModel(editor, parent, curve, component); }
catch (ArgumentException) { vm = null; }

Prevention

When it happens

Trigger: Constructing new Vector2ComponentCurveViewModel(editor, parent, computeCurve, VectorComponent.Z), typically from a generic curve-factory loop over components X..W.

Common situations: Curve creation code shared across Vector2/3/4; component lists derived from asset metadata that still mention Z; refactoring a Vector3 curve into Vector2 without updating components.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/967a4a4d0029462b. Report an issue: GitHub.

Appendix: source

Thrown at sources/editor/Stride.Assets.Presentation/CurveEditor/ViewModels/VectorComponentCurveViewModel.cs:99

        /// <param name="realPoint"></param>
        protected abstract void UpdateComponent(ref TValue value, Vector2 realPoint);

        /// <inheritdoc/>
        protected sealed override KeyFrameControlPointViewModel<TValue> CreateKeyFrameControlPoint(IMemberNode keyNode, IMemberNode valueNode, IMemberNode tangentTypeNode)
        {
            return (TKeyFrameControlPointViewModel)Activator.CreateInstance(typeof(TKeyFrameControlPointViewModel), this, keyNode, valueNode, tangentTypeNode, Component);
        }
    }

    /// <summary>
    /// Represents the curve of one component of a <see cref="Vector2"/>.
    /// </summary>
    public sealed class Vector2ComponentCurveViewModel : VectorComponentCurveViewModel<Vector2, Vector2ComponentControlPointViewModel>
    {
        public Vector2ComponentCurveViewModel([NotNull] CurveEditorViewModel editor, CurveViewModelBase parent, [NotNull] ComputeAnimationCurve<Vector2> computeCurve, VectorComponent component)
            : base(editor, parent, computeCurve, component)
        {
            if (component == VectorComponent.Z) throw new ArgumentException("Vector component 'Z' is invalid, only 'X' and 'Y' are supported.", nameof(component));
            if (component == VectorComponent.W) throw new ArgumentException("Vector component 'W' is invalid, only 'X' and 'Y' are supported.", nameof(component));
        }

        /// <inheritdoc/>
        protected override void UpdateComponent(ref Vector2 value, Vector2 realPoint)
        {
            // Update the component that is handled by this curve
            switch (Component)
            {
                case VectorComponent.X:
                    value.X = realPoint.Y;
                    break;

                case VectorComponent.Y:
                    value.Y = realPoint.Y;
                    break;

                default:

View on GitHub (pinned to 96fad776d2)