I wrote a postbuild script that deploys my builds to google drive. That works great, but when I tried to use the same type of logic on a pre build script, it fails. I'm trying to enable all game objects with the tag Mobile
if the platform is mobile (andriod or ios). Otherwise turn those off. This is what I have for a script:
#if UNITY_EDITOR
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
using UnityEditor;
public class PreBuild : IPreprocessBuildWithReport
{
public int callbackOrder => 0;
public void OnPreprocessBuild(BuildReport report)
{
var mobileGameObjects = GameObject.FindGameObjectsWithTag("Mobile");
switch (report.summary.platform) // todo: make sure all targets are populated here
{
// mobiles
case BuildTarget.Android:
case BuildTarget.iOS:
//enable all game objects
foreach (var mobileGameObject in mobileGameObjects)
{
mobileGameObject.SetActive(true);
}
break;
// standalones (desktops)
case BuildTarget.StandaloneWindows:
case BuildTarget.StandaloneLinux64:
case BuildTarget.StandaloneOSX:
foreach (var mobileGameObject in mobileGameObjects)
{
mobileGameObject.SetActive(false);
}
break;
// todo: consoles
}
}
}
#endif
The build runs fine, but when I run in mobile, none of the UI elements are there (off by default). Here is the heirarchy of them in my project: (screenshot not working):
- UI (Canvas Game Object)
- Mobile ("Empty" Game Object, is tagged with "Mobile")
- Joystick1
- Joystick2
- ActionButton
What am I missing?