Unity-Technologies/UnityCsReference · error · ArgumentException

There is no a valid NamedBuildTarget for BuildTargetGroup '{

Error message

There is no a valid NamedBuildTarget for BuildTargetGroup '{buildTargetGroup}'

What it means

FromBuildTargetGroup throws when the supplied BuildTargetGroup has no mapping in its switch statement. Each group must be explicitly handled; an unmapped group means Unity has no canonical NamedBuildTarget for it.

Source

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

                case BuildTargetGroup.LinuxHeadlessSimulation:
                    return NamedBuildTarget.LinuxHeadlessSimulation;
                case BuildTargetGroup.EmbeddedLinux:
                    return NamedBuildTarget.EmbeddedLinux;
                case BuildTargetGroup.QNX:
                    return NamedBuildTarget.QNX;

                // Build targets that are not explicitly listed
                case BuildTargetGroup.GameCoreXboxSeries:
                    return new NamedBuildTarget("GameCoreScarlett");
                case BuildTargetGroup.GameCoreXboxOne:
                    return new NamedBuildTarget("GameCoreXboxOne");
                case BuildTargetGroup.PS5:
                    return new NamedBuildTarget("PS5");
                case BuildTargetGroup.Kepler:
                    return new NamedBuildTarget("Kepler");
            }

            throw new ArgumentException($"There is no a valid NamedBuildTarget for BuildTargetGroup '{buildTargetGroup}'");
        }

        // TODO: We shouldn't be assuming that the namedBuildTarget can be extracted from the
        // active settings. This should be passed through the callstack instead when building.
        // We will need to use BuildTargetSelection (BuildTarget + Subtarget) that is in the cpp side.
        // For now this fixes an issue where Dedicated Server compiles with the Standalone settings.
        internal static NamedBuildTarget FromActiveSettings(BuildTarget target)
        {
            var buildTargetGroup = BuildPipeline.GetBuildTargetGroup(target);

            if (buildTargetGroup == BuildTargetGroup.Standalone && (StandaloneBuildSubtarget)EditorUserBuildSettings.GetActiveSubtargetFor(target) == StandaloneBuildSubtarget.Server)
            {
                return NamedBuildTarget.Server;
            }

            return NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup);
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Avoid calling FromBuildTargetGroup for unsupported/Unknown groups; branch on the known set first.
  2. Prefer NamedBuildTarget.FromActiveSettings(BuildTarget) which has Standalone subtarget handling, instead of the raw group mapping.
  3. If the group is genuinely new, add an explicit case to FromBuildTargetGroup returning its canonical NamedBuildTarget.

Example fix

// before
var nbt = NamedBuildTarget.FromBuildTargetGroup(someGroup); // may throw

// after
if (someGroup == BuildTargetGroup.Unknown)
    throw new ArgumentException("Cannot resolve NamedBuildTarget for Unknown group.");
var nbt = NamedBuildTarget.FromBuildTargetGroup(someGroup);
Defensive patterns

Strategy: validation

Validate before calling

switch (buildTargetGroup)
{
    case BuildTargetGroup.Unknown:
        throw new ArgumentException("Cannot resolve NamedBuildTarget for Unknown group.");
    // ... add explicit handling for known groups ...
}

Type guard

static bool IsResolvableGroup(BuildTargetGroup g) => g switch {
    BuildTargetGroup.Standalone => true,
    BuildTargetGroup.Android => true,
    BuildTargetGroup.iOS => true,
    // enumerate the handled cases
    _ => false };
if (!IsResolvableGroup(group)) return null;

Prevention

When it happens

Trigger: Calling NamedBuildTarget.FromBuildTargetGroup(buildTargetGroup) with a group not covered by the switch (e.g. an Unknown, deprecated, or newly added BuildTargetGroup enum value before the mapping is updated).

Common situations: A new platform module registers a BuildTargetGroup enum value but the NamedBuildTarget mapping wasn't updated in lockstep; calling with BuildTargetGroup.Unknown; reflection/introspection iterating all enum values.

Related errors


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