'Detect if build target is installed

I maintain an editor extension called Build Automator and I wanted to upgrade it so that it would disable any platforms that the user does not have installed; I did some searching through the docs but couldn't find anything.

I was wondering if there's any way to detect if a module is installed, or if a build target exists?



Solution 1:[1]

I don't think there is a public API for it. But of course you can still get there with a bit of reflection. Whether or not you should go there depends on how reliable you want things to be.

The BuildPipeline has the following static method

internal static extern bool IsBuildTargetSupported(BuildTarget target);

You could invoke it as follows:

MethodInfo buildTargetSupported = typeof(BuildPipeline).GetMethod("IsBuildTargetSupported", BindingFlags.Static | BindingFlags.NonPublic);
if(Convert.ToBoolean(buildTargetSupported.Invoke(null, new object[] { BuildTarget.PS4 })))
{
    Debug.Log("PS4 Supported");
}
if (Convert.ToBoolean(buildTargetSupported.Invoke(null, new object[] { BuildTarget.Android })))
{
    Debug.Log("Android Supported");
}
//etc

It's not great, and if there is a public API I have overlooked, you should definitely use that. But in a pinch it may do.

Solution 2:[2]

Just wanted to add that Unity has made this method public i e: BuildPipeline.IsTargetPlatformSupported

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Titantompa