Unity-Technologies/UnityCsReference · error · ArgumentException

' ' is not a valid subtarget for the Standalone build target

Error message

'{standaloneSubtarget}' is not a valid subtarget for the Standalone build target

What it means

When resolving a NamedBuildTarget for a Standalone target from a subtarget integer, only Player and Server are accepted. Any other StandaloneBuildSubtarget enum value hits the default case and throws ArgumentException.

Solutions

  1. Ensure the subtarget passed is StandaloneBuildSubtarget.Player or StandaloneBuildSubtarget.Server.
  2. If a new subtarget was added, extend the switch to map it to a NamedBuildTarget.
  3. Use NamedBuildTarget.FromActiveSettings(target) which derives the correct subtarget from active settings.

Example fix

// before
var nbt = NamedBuildTargetInternal.GetNamedBuildTarget(target, rawSubtarget);

// after
var sub = (StandaloneBuildSubtarget)rawSubtarget;
if (sub != StandaloneBuildSubtarget.Player && sub != StandaloneBuildSubtarget.Server)
    throw new ArgumentOutOfRangeException(nameof(rawSubtarget), sub, "Only Player/Server standalone subtargets are supported.");
var nbt = NamedBuildTargetInternal.GetNamedBuildTarget(target, rawSubtarget);
Defensive patterns

Strategy: validation

Validate before calling

var sub = (StandaloneBuildSubtarget)subtarget;
if (sub != StandaloneBuildSubtarget.Player && sub != StandaloneBuildSubtarget.Server)
    throw new ArgumentOutOfRangeException(nameof(subtarget), sub, "Only Player/Server subtargets are valid for Standalone.");

Type guard

static bool IsValidStandaloneSubtarget(int sub) =>
    Enum.IsDefined(typeof(StandaloneBuildSubtarget), sub) &&
    ((StandaloneBuildSubtarget)sub is StandaloneBuildSubtarget.Player or StandaloneBuildSubtarget.Server);

Prevention

When it happens

Trigger: Calling the internal GetNamedBuildTarget(target, subtarget) where the target is in the Standalone group and the subtarget integer casts to a StandaloneBuildSubtarget value other than Player (0) or Server (1).

Common situations: A future StandaloneBuildSubtarget enum member added without updating this switch; passing a raw subtarget integer that does not correspond to a valid member; platform extension injecting a custom standalone subtarget.

Related errors


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

Appendix: source

Thrown at Editor/Mono/BuildPipeline/NamedBuildTarget.cs:192

            }

            return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
        }

        internal static NamedBuildTarget FromTargetAndSubtarget(BuildTarget target, int subtarget)
        {
            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);
            if (buildTargetGroup == BuildTargetGroup.Standalone)
            {
                var standaloneSubtarget = (StandaloneBuildSubtarget)subtarget;
                switch (standaloneSubtarget)
                {
                    case StandaloneBuildSubtarget.Player:
                        return NamedBuildTarget.Standalone;
                    case StandaloneBuildSubtarget.Server:
                        return NamedBuildTarget.Server;
                    default:
                        throw new ArgumentException($"'{standaloneSubtarget}' is not a valid subtarget for the Standalone build target");
                }
            }

            return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
        }

        [ExcludeFromDocs]
        public static bool operator==(NamedBuildTarget lhs, NamedBuildTarget rhs)
        {
            return lhs.Equals(rhs);
        }

        [ExcludeFromDocs]
        public static bool operator!=(NamedBuildTarget lhs, NamedBuildTarget rhs)
        {
            return !lhs.Equals(rhs);
        }

View on GitHub (pinned to 225b0fbdb5)