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
- Avoid calling FromBuildTargetGroup for unsupported/Unknown groups; branch on the known set first.
- Prefer NamedBuildTarget.FromActiveSettings(BuildTarget) which has Standalone subtarget handling, instead of the raw group mapping.
- 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
- Prefer NamedBuildTarget.FromActiveSettings(target) over FromBuildTargetGroup.
- Branch on the known group set before calling FromBuildTargetGroup.
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
- '{targetName}' is not a valid build target name
- Build profile is invalid.
- The 'locationPathName' parameter for BuildPipeline.BuildPlay
- For the '{0}' target the 'locationPathName' parameter for Bu
- '{standaloneSubtarget}' is not a valid subtarget for the Sta
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ded5a689b2ea83f4.
Report an issue: GitHub.