Unity-Technologies/UnityCsReference · error · ArgumentException

Platform GUID {platformGuid} is not a valid Unity build plat

Error message

Platform GUID {platformGuid} is not a valid Unity build platform.

What it means

Thrown by ValidatePlatformExists(GUID) when the supplied platformGuid does not match any platform returned by BuildTargetDiscovery.GetAllPlatforms(). This is a stricter check than error 129: it verifies the GUID is a known Unity platform at all, regardless of whether it is installed. If the GUID is not in the full platform enumeration, the method throws ArgumentException.

Source

Thrown at Editor/Mono/BuildProfile/BuildProfile.Create.cs:198

            // Notify the UI of creation so that the new build profile can be selected
            onBuildProfileCreated?.Invoke(buildProfile);
            return buildProfile;
        }

        /// <summary>
        /// Validates that the platform GUID corresponds to a known Unity platform.
        /// Does NOT check if the platform module is installed.
        /// </summary>
        static void ValidatePlatformExists(GUID platformGuid)
        {
            foreach (var guid in BuildTargetDiscovery.GetAllPlatforms())
            {
                if (guid == platformGuid)
                    return;
            }

            throw new ArgumentException(
                $"Platform GUID {platformGuid} is not a valid Unity build platform.");
        }

        /// <summary>
        /// Validates if the provided path name length is supported by the Asset database.
        /// Throws an ArgumentException if the platform is not valid.
        /// </summary>
        /// <param name="assetPath">The path to the build profile to be created.</param>
        static void ValidateFileNameLength(string assetPath)
        {
            var byteCount = System.Text.Encoding.UTF8.GetByteCount(Path.GetFileName(assetPath));
            // File name length is limited by the asset database
            if (byteCount > BuildProfileModuleUtil.k_MaxAssetFileNameLength)
                throw new ArgumentException($"Build profile name is too long ({byteCount}) - max supported is {BuildProfileModuleUtil.k_MaxAssetFileNameLength} bytes.");
        }

        internal void NotifyBuildProfileExtensionOfCreation(int preconfiguredSettingsVariant)
        {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Obtain the platform GUID from BuildTargetDiscovery.GetAllPlatforms() at runtime rather than hardcoding it.
  2. Validate the GUID against GetAllPlatforms() before calling the create API.
  3. If the GUID came from a saved profile, re-resolve it against the current Unity version's platform list.

Example fix

// before
BuildProfile.Create(myHardcodedGuid, name);

// after
var valid = BuildTargetDiscovery.GetAllPlatforms().Any(g => g == myHardcodedGuid);
if (!valid) throw new InvalidOperationException("GUID is not a known platform.");
BuildProfile.Create(myHardcodedGuid, name);
Defensive patterns

Strategy: validation

Validate before calling

if (!BuildTargetDiscovery.GetAllPlatforms().Contains(platformGuid)) throw new InvalidOperationException("Unknown platform GUID.");

Type guard

static bool IsValidPlatformGuid(UnityEditor.GUID g) => BuildTargetDiscovery.GetAllPlatforms().Contains(g);

Prevention

When it happens

Trigger: Passing a malformed, random, or outdated GUID as platformId to the profile creation flow. ValidatePlatformExists is called during creation and rejects unknown GUIDs before any module-installation check.

Common situations: Hardcoded GUID that became invalid after a Unity version change; copy/paste error in a platform GUID; passing a GUID obtained from an unrelated system; serialization corruption of the platform GUID field.

Related errors


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