Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Obtaining BuildTargetGroup from activeBuildTarget

Discussion in 'Scripting' started by Lohoris2, Apr 12, 2017.

  1. Lohoris2

    Lohoris2

    Joined:
    Aug 20, 2013
    Posts:
    86
    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?
     
  2. zaniocz

    zaniocz

    Joined:
    May 9, 2011
    Posts:
    21
    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);
     
  3. Lohoris2

    Lohoris2

    Joined:
    Aug 20, 2013
    Posts:
    86
    I understand that, however this doesn't help at all, unfortunately.

    As I said:

     
  4. zaniocz

    zaniocz

    Joined:
    May 9, 2011
    Posts:
    21
    "...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 ();
     
    turbanov and Lohoris2 like this.
  5. Astiolo

    Astiolo

    Joined:
    Dec 18, 2014
    Posts:
    27
    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.
     
  6. Garrafote

    Garrafote

    Joined:
    Jun 13, 2013
    Posts:
    42
    Hi,

    You can use BuildPipeline.GetBuildTargetGroup:

    var target = EditorUserBuildSettings.activeBuildTarget;
    var group = BuildPipeline.GetBuildTargetGroup(target);
     
  7. Jean-Fabre

    Jean-Fabre

    Joined:
    Sep 6, 2007
    Posts:
    378
    Thanks for this this, this is much better than trying to maintain a list over time of all the messy changes of the enum :)

    Bye,

    Jean
     
    bmccowan and Garrafote like this.
  8. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    62
unityunity