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?

Good timing. I just recently sought after a solution for this a few days ago for a platform switcher I was working on. I don’t know if I found the preferred solution (I would love to know if there is an easier way), but by using Reflection I was able to access the ModuleManager to check IsPlatformSupportLoaded.

var moduleManager = System.Type.GetType("UnityEditor.Modules.ModuleManager,UnityEditor.dll");
var isPlatformSupportLoaded = moduleManager.GetMethod("IsPlatformSupportLoaded", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
var getTargetStringFromBuildTarget = moduleManager.GetMethod("GetTargetStringFromBuildTarget", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic);
return (bool)isPlatformSupportLoaded.Invoke(null,new object[] {(string)getTargetStringFromBuildTarget.Invoke(null, new object[] {BuildTarget.tvOS})});