stride3d/stride · error · ArgumentException

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

Error message

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

What it means

Declared on Vector2ComponentCurveViewModel and its derived classes to signal that the Component assigned to a Vector2 component curve is invalid. A Vector2 only has X and Y components, so creating a curve view model bound to the W component is not supported and raises this error during curve editor initialization.

Solutions

  1. Pass only VectorComponent.X or VectorComponent.Y
  2. Enumerate components according to the curve's vector dimension
  3. Filter out W entries when curves change type
  4. Catch ArgumentException to tolerate bad descriptors

Example fix

// before
foreach (var c in new[] { X, Y, Z, W }) new Vector2ComponentCurveViewModel(editor, parent, curve, c);
// after
foreach (var c in new[] { VectorComponent.X, VectorComponent.Y }) new Vector2ComponentCurveViewModel(editor, parent, curve, c);
Defensive patterns

Strategy: validation

Validate before calling

if (!IsValidVector2Component(component)) 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(..., VectorComponent.W), usually from a shared component enumeration applied to all vector curve types.

Common situations: Component loops written for Vector4; asset channels carrying W after a type change to Vector2; copy-pasted curve descriptors.

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/754a3cb35e8509b7. Report an issue: GitHub.

Appendix: source

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

        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:
                    throw new NotSupportedException(); // This should never happen

View on GitHub (pinned to 96fad776d2)