Obtaining BuildTargetGroup from activeBuildTarget

I’m using EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTarget), and now I’ve got a warning claiming it’s obsolete, suggesting to use SwitchActiveBuildTarget(BuildTargetGroup,BuildTarget) instead.

I’m getting the BuildTarget from EditorUserBuildSettings.activeBuildTarget, and I haven’t found a way to get the active BuildTargetGroup instead, so I have no way to prevent this warning (save disabling it with pragma, of course).

Furthermore, the new overload of this method is undocumented: the documentation only list the original one, marked as obsolete, with no replacement.

Is there the possibility to get the active BuildTargetGroup, or at least will it be added before completely removing the original method?

Hi Lohoris2,

I suspect that this is happening to you in 5.6.0f3 onwards.
The warning was created with the addition of the facebook platform since you need to specify BuildTargetGroup.Facebook and BuildTarget.StandaloneWindows to switch to Facebook properly, you can prevent this warning specifying the same target in BuildTargetGroup and BuildTarget, for example, to switch to android you can do:
EditorUserBuildSettings.SwitchActiveBuildTarget (BuildTargetGroup.Android, BuildTarget.Android);
but for facebook you should specify:
UnityEditor.EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Facebook, BuildTarget.StandaloneWindows);

I understand that, however this doesn’t help at all, unfortunately.

As I said:

“…Is there the possibility to get the active BuildTargetGroup…”

I think what you need to get the active BuildTargetGroup is the selectedBuildTargetGroup method*:*
string BuildTargetGroupSelected = EditorUserBuildSettings.selectedBuildTargetGroup.ToString ();

4 Likes

That works most of the time but unfortunately it’s not always correct. With my script it just doesn’t work when the selected group isn’t set to match the active active build target. So I have to remember to make sure they match, it would be much nicer to be able to just get the currently active group. Maybe it’s a Unity bug that they don’t match sometimes but either way it’s a bit of a pain.

Hi,

You can use BuildPipeline.GetBuildTargetGroup:

var target = EditorUserBuildSettings.activeBuildTarget;
var group = BuildPipeline.GetBuildTargetGroup(target);

20 Likes

Thanks for this this, this is much better than trying to maintain a list over time of all the messy changes of the enum :slight_smile:

Bye,

Jean

3 Likes

Thanks, I won’t have to make my own mapping/if blocks/switch-case with that. Too bad GetBuildTargetGroup is undocumented and therefore not searchable in API (Unity - Scripting API: BuildPipeline). At least it shows in BuildPipeline member autocompletion.

2 Likes