Hello everyone 
In unity, there’s the BuildPipeline.BuildPlayer method…
I was wondering wether this ( or something else in the buildPipeline class ) were able to exclude gameObjects from the build just like with the ‘EditorOnly’ tag but with a custom tag like for example ‘AndroidOnly’ ?
does anyone know what is behind the scenes for EditorOnly tag ?
Thx for your answers 
Bump ???
Anyone could please give me some clues on this ? 
Thanks a lot !
hmmm strange that nobody knows this ? 
well i guess i’ll have to find the solution on my own 
This is the first I’ve seen of your message in the areas where I commonly look.
I use this script to remove all static lightmap flags from my scenes, such that I can be lazy and not remember to turn off light baking, as I never want baked lights and ProBuilder CONSTANTLY reasserts the static lightmap flag every time I edit anything.
It should be easy to change the loop to do FindObjectsOfType() and Destroy() them… give it a try!
2 Likes
Unfortunately there isn’t a system for platform specific tags like there is for EditorOnly. The solution above is definitely one way to solve it. Some people also use Addressables and flip the “Include in Build” flag based upon the platform. That way you keep the same key for an asset, but use different actual assets under the hood.
2 Likes
You can use the PostProcessSceneAttribute and destroy all game objects returned by GameObject.FindGameObjectsWithTag.
Stripping game objects from prefabs is a much more complicated ordeal. But there is an asset called Exclude From Build that can help you pull it off in this situation as well, if it’s necessary.
1 Like
hi @Kurt-Dekker
This looks like a really sexy solution 
I’ll try this and will give you feedback here 
Thanks a lot and happy unitying !!!
EDIT: Was too sexy to be true 
ok… after i understood this script has to be in an editor folder, how can i call destroy or immediate on objects ?
@Kurt-Dekker and @sisus_co
EDIT2: ok… GameObject.Destroy(g);
no i have to figure out how to do this BEFORE build and not after 
EDIT3: DestroyImmediate has to be called instead of Destroy…
Unfortunately objects are destroyed in the scene, but after build. They are still present in the .exe 
EDIT4:
Finally it works with this:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
class MyCustomBuildProcessor : IProcessSceneWithReport//IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnProcessScene(UnityEngine.SceneManagement.Scene scene, BuildReport report)//OnPreprocessBuild(BuildReport report)
{
Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath);
plop();
}
void plop()
{
List<GameObject> ToChange = new List<GameObject>();
Transform[] trs = GameObject.FindObjectsOfType<Transform>();
foreach( Transform tr in trs)
{
if(tr!=null)
{
GameObject go = tr.gameObject;
Debug.Log("GO="+go.name+" ---> "+go.tag);
if (go.tag=="Android")
{
Debug.Log("deleted="+go.name);
GameObject.DestroyImmediate(go);
}
}
}
}
}
Object tagged ‘Android’ is not in .exe anymore and editor scene still contains the object.
Now i have to be sure this can work for all scenes in the app 