Search Unity

Excluding folders from build

Discussion in 'Editor & General Support' started by YondernautsGames, Jun 1, 2016.

  1. jacobfdunbar

    jacobfdunbar

    Joined:
    Jun 25, 2015
    Posts:
    16
    +1 to follow this. Would immensely help my workflow!
     
  2. Cobo3

    Cobo3

    Joined:
    Jun 16, 2013
    Posts:
    67
    I found a working solution, at least for my needs, using Unity 2019.4.

    Following the guidelines under Special Folders, before making the build, I rename every file I don't want included and add ".tmp" at the end. Once the build is complete, I revert the process so that git doesn't complain.

    This removes the files from the build, effectively reducing its size :)

    Here's the snippet I used
    Code (CSharp):
    1.  
    2. using System.IO;
    3. using UnityEditor;
    4. using UnityEditor.Build;
    5. using UnityEditor.Build.Reporting;
    6.  
    7. public class DeleteUnnecessaryResources : IPreprocessBuildWithReport, IPostprocessBuildWithReport
    8. {
    9.     string[] paths = new string[]
    10.     {
    11.         //Application.dataPath + "/Resources/" etc...
    12.     };
    13.  
    14.     public int callbackOrder => default;
    15.  
    16.     public void OnPreprocessBuild(BuildReport report)
    17.     {
    18.         if (!report.summary.options.HasFlag(BuildOptions.Development))
    19.             for (int i = 0; i < paths.Length; i++)
    20.                 File.Move(paths[i], paths[i] + ".tmp");
    21.     }
    22.  
    23.     public void OnPostprocessBuild(BuildReport report)
    24.     {
    25.         if (!report.summary.options.HasFlag(BuildOptions.Development))
    26.             for (int i = 0; i < paths.Length; i++)
    27.                 File.Move(paths[i] + ".tmp", paths[i]);
    28.         AssetDatabase.Refresh();
    29.     }
    30. }
    31.  
     
  3. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    You should replace File.Move with:

    https://docs.unity3d.com/ScriptReference/AssetDatabase.MoveAsset.html

    Otherwise you could break meta file references.
     
    Sergey_Droba and Cobo3 like this.
  4. eusebium

    eusebium

    Joined:
    Jul 23, 2016
    Posts:
    84
  5. marcb152

    marcb152

    Joined:
    Jun 20, 2019
    Posts:
    22
    You should replace ".tmp" by "~", this works for both files and folders.
    Here's a working script (tested in Unity 2019.3.1f1).
    You'll need to put this script in an "Editor" folder.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using System.IO;
    3. using UnityEditor;
    4. using UnityEditor.Build;
    5. using UnityEditor.Build.Reporting;
    6.  
    7. public class ExcludeFromBuild : IPreprocessBuildWithReport, IPostprocessBuildWithReport
    8. {
    9.     /*
    10.      * Project relative path :
    11.      * --> "Assets\Prefabs\..."
    12.      */
    13.     public List<string> paths = new List<string>()
    14.     {
    15.         @"Assets\Skybox\Cubemaps"
    16.     };
    17.  
    18.     public int callbackOrder => default;
    19.  
    20.     public void OnPreprocessBuild(BuildReport report)
    21.     {
    22.         if (!report.summary.options.HasFlag(BuildOptions.Development))
    23.             for (int i = 0; i < paths.Count; i++)
    24.                 //Since we "create" an hidden folder or file, Unity will remove the META files associated with them
    25.                 AssetDatabase.MoveAsset(paths[i], paths[i] + "~");
    26.         AssetDatabase.Refresh();
    27.     }
    28.  
    29.     public void OnPostprocessBuild(BuildReport report)
    30.     {
    31.         if (!report.summary.options.HasFlag(BuildOptions.Development))
    32.             for (int i = 0; i < paths.Count; i++)
    33.                 //No more META files to consider, so we can use File.Move()
    34.                 File.Move(paths[i] + "~", paths[i]);
    35.         AssetDatabase.Refresh();
    36.     }
    37. }
    38.  
     
    DungDajHjep, samanabo and Cobo3 like this.
  6. EusebiuMarcu

    EusebiuMarcu

    Joined:
    Sep 20, 2018
    Posts:
    26
    Indeed, the problem was with the Application.dataPath. Relative paths must be used.
     
    marcb152 likes this.
  7. Jelmer123

    Jelmer123

    Joined:
    Feb 11, 2019
    Posts:
    243
    So how is Unity a multi platform editor when, really, you can't specify what and what not to include in certain builds? :p

    I'm using Cloud build for Android and iOS, but now I'm about to face the same problems as other here.
    I'm also looking into a project targeting desktop and VR. So in one I want to include the Oculus SDK, and the other I don't.
     
  8. Yacuzo

    Yacuzo

    Joined:
    Sep 22, 2016
    Posts:
    27
    Jelmer123 likes this.
  9. YondernautsGames

    YondernautsGames

    Joined:
    Nov 24, 2014
    Posts:
    354
    Can you use asset bundles like that with Plugin folders? The thing that started the issue for me was building for multiple android platforms, which all had their own plugins
     
  10. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    In this thread we are not talking about code, we are talking about assets.

    I haven't used the Addressables much so correct me if I am wrong.

    I don't think Addressables are a solution because if you have all the contents (for different platforms) in your StreamingAssets or Resources folder, it is useless.

    In other words, the Addressables asset serves to solve an asset from different sources but does not alter the Unity build by including or excluding assets from the build.
     
    Cobo3 and jashan like this.
  11. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I'm honestly curious about this. Has any tool already come up yet to manage what we could simply call "building setups" or presets?
    I find the idea of having to rename assets or literally deleting some before a building to be a mediocre method of asset management.
    I'm getting into the adressable assets function but I'm not sure it's what we're looking for and the documentation alone remains rather cryptic.
     
  12. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
  13. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I think that without any "built in" support from Unity, any tool that someone might create will be based around the idea of moving things around / renaming things. It will just be more "automatic".

    I have already built 2 such tools but they are far from perfect, however they get the job done :)
     
  14. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    I see, ghetto ways of handling ... problems.
    I was looking at my build reports and there's so much tripe that gets included but I find it equally stupid to either delete or rename the files. I looked into the adressables but it's very daunting, plus it requires more scripts and the use of placeholders does leave a layer of mystery regarding the use of one's assets until said placeholders actually get filled with whatever goes in the empty slot at a given time during runtime. It almost smells like overbearing reflection.
    i'm puzzled that there's no native and intuitive system to edit pre-build lists of asset inclusion/exclusion based on project targets, that would eventually also be synchronizable with repos and more.
    Unity seems to provide the beginning of a solution with their own service (dunno, didn't try anything like that yet, just read stuff on the forum) but that's cumbersome when this should be easily available locally.
     
  15. oobartez

    oobartez

    Joined:
    Oct 12, 2016
    Posts:
    167
    We have just hit the same wall as everyone else while preparing a demo version of our game. None of the solutions available in Unity allow you to selectively include/exclude assets. An ideal solution would allow you to somehow prefilter assets depending on your own conditions. For example, AssetPostprocessor.OnPreprocessAsset could expose an API for deciding whether an asset should or should not be included in the build.

    The tildes etc. are really just ugly hacks by any measure which mess up your VCS. (This isn't attacking people who use it since Unity doesn't give you an alternative.)
     
  16. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    I'm not sure if you have seen my earlier posting on this, it's #23: https://forum.unity.com/threads/excluding-folders-from-build.408375/#post-3563669

    Tbh, after having worked with this solution for several years now, I don't see how Unity adding their own thing would give anyone much of a benefit. For example, hooking this up with the build targets would not solve our problem (we usually build to Windows, with different configurations).

    We currently have several different versions of the project in different folders, and that gives us the perfect workflow. By using Git's sparse-checkout, I don't waste any harddisk space because each project version only has the files that it really needs. Putting all of this into a single instance of the project would not help our workflow. Also, it makes navigating the project much easier and speeds up re-imports on Unity updates.

    In general, I think Unity should focus on their core business - the game engine. And for something like this, version control actually seems to me like it's the best solution. Not sure if other version control systems (VCSs) have the same feature but Git does and it seems like it has become the defacto standard. So if you're using another VCS and it doesn't have an equivalent feature, that would probably be a worthwhile feature request for the VCS provider.
     
    vecima likes this.
  17. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    @jashan, Nice post, thank you. A bit technical, I'll keep it under the thumb. Obviously this kind of management would imply a tool of its own, and somehow a minor interface of its own too.
    I can see the benefit of this unless Unity's native tool would also come with the option to hide the assets that are not meant to be pushed into the build. I understand why it's obviously faster today to go with a third party service that already has all the functions to manage variants of a same project and allows workers to download a clean version of the project, with no risk of messing up a file or something, especially in light of the "delete or tilde" absurd solution.
    The reimport aspect of the workflow, which happens often enough to be taken seriously, is understandably important to keep an eye on. Maybe assets that are to be updated or (re)imported could be filtered based on the list though?
    The problem to me is that for something that seems so essential and useful, the solution actually comes from outside of Unity. It's not like we're asking for them to recode their own complex VCS either. I may be missing something here but I do not think it would be out of reach to have an ability to do that filtering, one to control the used assets, the visibility, the importability, etc., that would be open enough to be compatible with some random VCS if one studio wants to push the envelope further. Unity is already capable of hiding Game Objects and assets for example.
     
  18. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,307
    In general, I think that this is actually kind of a special thing that only comparatively few projects will need. However, there's one issue that would need to be solved by Unity: With this approach, or even just conditional compilation (which is very commonly used), it's possible that depending on the state of the project, certain MonoBehaviours may not be available. So, Unity should have a mode where MonoBehaviours that don't exist are completely ignored and hidden (but this needs to be "opt-in" because in general, Unity throwing warnings when a MonoBehaviour is missing is really important).

    Even more important, some GameObjects may not be relevant depending on the state, and having them included in the scene may actually be harmful. With the new Prefab system, this doesn't work for prefabs. So those are the two things that I think would be needed:
    1. Being able to properly "remove" MonoBehaviours depending on different states of the project
    2. Being able to properly "remove" GameObjects, also if they are part of prefabs, depending on project state
    Other than that, I think a solution outside Unity has the benefit of not making Unity even more complex than it already is. Keep in mind that even with a large team, adding more complexity creates a lot of problems that eventually result in bugs and instability of the engine.

    Now, having a solution that properly handles different render pipelines in a single project (e.g. legacy and URP, depending on build target) would be kind of a similar request - but this can only be handled inside Unity. There's no external workaround. So, if there was a choice between handing "removing files generically", and "handling different render pipelines in a single project properly", I would absolutely want the latter.
     
  19. otter-blitz-studio

    otter-blitz-studio

    Joined:
    Oct 3, 2020
    Posts:
    3
    Hey,

    maybe this helps someone:
    I created in the /Editor folder a file named BuildFolderExcluder.cs and there I add a "." in front of all folders which should not be included in my build. And afterwards I revert it.

    BuildFolderExcluder.cs
    Code (CSharp):
    1.  
    2. using System.Collections.Generic;
    3. using System.IO;
    4. using System.Linq;
    5. using UnityEditor;
    6. using UnityEditor.Build;
    7. using UnityEditor.Build.Reporting;
    8. using UnityEngine;
    9.  
    10. [InitializeOnLoad]
    11. class BuildFolderExcluder : IPreprocessBuildWithReport, IPostprocessBuildWithReport {
    12.  
    13.     static List<ExcludeFolder> pathAndFoldersToExclude = new List<ExcludeFolder> () {
    14.         new ExcludeFolder ("Assets/Resources/png/_static/", "android", new ExcludeFolder.Platform[] { ExcludeFolder.Platform.UNITY_STANDALONE, ExcludeFolder.Platform.UNITY_IOS }),
    15.         new ExcludeFolder ("Assets/Resources/png/_static/", "apple", new ExcludeFolder.Platform[] { ExcludeFolder.Platform.UNITY_STANDALONE, ExcludeFolder.Platform.UNITY_ANDROID })
    16.     };
    17.  
    18.     static BuildFolderExcluder () {
    19.         RevertFolders (pathAndFoldersToExclude);
    20.     }
    21.  
    22.     public int callbackOrder { get { return 0; } }
    23.     public void OnPreprocessBuild (BuildReport report) {
    24.         Application.logMessageReceived += OnBuildError;
    25. #if UNITY_STANDALONE
    26.         this.ExcludeFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_STANDALONE)).ToList ());
    27. #elif UNITY_IOS
    28.         this.ExcludeFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_IOS)).ToList ());
    29. #elif UNITY_ANDROID
    30.         this.ExcludeFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_ANDROID)).ToList ());
    31. #endif
    32.     }
    33.  
    34.     private void OnBuildError (string condition, string stacktrace, LogType type) {
    35.         if (condition != null && condition.ToUpper ().Contains ("Build completed".ToUpper ())) {
    36.             this.RevertFoldersForPlatforms ();
    37.         }
    38.     }
    39.  
    40.     public void OnPostprocessBuild (BuildReport report) {
    41.         this.RevertFoldersForPlatforms ();
    42.     }
    43.  
    44.     private void ExcludeFolders (List<ExcludeFolder> folders) {
    45.         for (int i = 0; i < folders.Count; i++) {
    46.             Directory.Move (string.Format ("{0}{1}", folders[i].path, folders[i].folder), string.Format ("{0}.{1}", folders[i].path, folders[i].folder));
    47.         }
    48.     }
    49.  
    50.     private void RevertFoldersForPlatforms () {
    51.         Application.logMessageReceived -= OnBuildError;
    52. #if UNITY_STANDALONE
    53.         RevertFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_STANDALONE)).ToList ());
    54. #elif UNITY_IOS
    55.         RevertFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_IOS)).ToList ());
    56. #elif UNITY_ANDROID
    57.         RevertFolders (pathAndFoldersToExclude.Where (folder => folder.platformsToExclude.Contains (ExcludeFolder.Platform.UNITY_ANDROID)).ToList ());
    58. #endif
    59.     }
    60.  
    61.     static void RevertFolders (List<ExcludeFolder> folders) {
    62.         for (int i = 0; i < folders.Count; i++) {
    63.             if (Directory.Exists (string.Format ("{0}{1}", folders[i].path, folders[i].folder)) &&
    64.                 Directory.Exists (string.Format ("{0}.{1}", folders[i].path, folders[i].folder))) {
    65.                 Directory.Delete (string.Format ("{0}{1}", folders[i].path, folders[i].folder));
    66.                 Directory.Move (string.Format ("{0}.{1}", folders[i].path, folders[i].folder), string.Format ("{0}{1}", folders[i].path, folders[i].folder));
    67.             }
    68.         }
    69.     }
    70. }
    ExcludeFolder.cs:
    Code (CSharp):
    1.  
    2. public class ExcludeFolder {
    3.     public enum Platform {
    4.         UNITY_STANDALONE,
    5.         UNITY_IOS,
    6.         UNITY_ANDROID,
    7.     }
    8.  
    9.     public string path;
    10.     public string folder;
    11.     public Platform[] platformsToExclude;
    12.  
    13.     public ExcludeFolder (string path, string folder, Platform[] platformsToExclude) {
    14.         this.path = path;
    15.         this.folder = folder;
    16.         this.platformsToExclude = platformsToExclude;
    17.     }
    18. }
    19.  
     
    Last edited: Feb 2, 2021
    DungDajHjep likes this.
  20. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,052
    Be careful because these interfaces do not always work:

    https://forum.unity.com/threads/ipo...mbarrasing-answer-about-a-serious-bug.891055/
     
  21. otter-blitz-studio

    otter-blitz-studio

    Joined:
    Oct 3, 2020
    Posts:
    3
    True.
    That's why I tried to handle it with:

    Code (CSharp):
    1. Application.logMessageReceived += OnBuildError;

    Code (CSharp):
    1.  private void OnBuildError (string condition, string stacktrace, LogType type) {
    2.         if (condition != null && condition.ToUpper ().Contains ("Build completed".ToUpper ())) {
    3.             this.RevertFoldersForPlatforms ();
    4.         }
    5.     }
    I don't know if it works all the time but I saw 2 messages:
    Build completed with a result of 'Succeeded'
    Build completed with a result of 'Cancelled'


    And at this point, we don't care about the result.
     
  22. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Eh? Didn't you mean you don't care about the method as long as you get the good result?
     
  23. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Unity could use something like the Audio Mixer where you can ignore/hide elements.
    In this case each "mixer" would correspond to a specific set up.
     
  24. otter-blitz-studio

    otter-blitz-studio

    Joined:
    Oct 3, 2020
    Posts:
    3
    Sorry for the confusion, I meant that this.RevertFoldersForPlatforms() should be called after the "Build completed" no matter if the result is positive or negative.
     
  25. Menion-Leah

    Menion-Leah

    Joined:
    Nov 5, 2014
    Posts:
    189
  26. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    +1 as well.
    This would really help a lot of people.
     
    Menion-Leah likes this.
  27. goldenPiGames

    goldenPiGames

    Joined:
    Sep 19, 2021
    Posts:
    1
    + a very large number
    Seriously, what? How is this not a thing? I've only recently started trying to use Unity because it was recommended as the most versatile engine, but can you really say that's true if it isn't even capable of something as simple as excluding files through build options? Some of us have specifications that involve including files on platforms but not on others.
     
    bdovaz, ModLunar and Menion-Leah like this.
  28. Gasimo

    Gasimo

    Joined:
    Mar 3, 2015
    Posts:
    68
    You could explicitly cite what will get included in which platform using the Addressables system.
     
  29. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
  30. LaurieAnnis

    LaurieAnnis

    Joined:
    Jan 24, 2010
    Posts:
    63
  31. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    +1

    ~ sounds good but according to the docs it only ignores files during import. I have a ton of textures that I have in the project that I use to build a texture array. I want them in the project since it saves a lot of time when trying to edit a texture but there is no need for them in the final build.

    I'm guessing I could use the scriptable build pipeline to handle this but feels like overkill for such a simple task :/
     
  32. LaireonGames

    LaireonGames

    Joined:
    Nov 16, 2013
    Posts:
    705
    Wow what a joke... so looks like the scriptable build pipeline isn't designed for this (it might have something in there under the hood but I didn't feel like wading through learning it for a simple task).

    On top of this, the Editor folder trick doesn't fully work because it doesn't handle sub folders.... So your assets have to sit directly within an Editor folder and can't be a folder within that, pretty horrific design! Makes me wonder if the Editor folder even works at all....

    As a side note, you can use the Build Report Inspector package to track if assets have been included but its also a joke, think its been in preview for 2 years now and its performance is horrific when trying to browse source assets to the point of being unusable. I wouldn't mind but it took me all of 5 mins to fix it which begs the question, what the hell are Unity doing and why did I need to do that?
     
    ModLunar likes this.
  33. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Well at least putting the ~ at the end of a folder masks said folder from the Project window, implying that it won't get included in the build. I did a quick test and it worked fine for a simple project. But I only tried on a normal folder that wasn't:
    • Editor (that would be illogical and pointless anyway)
    • Resources
    • Streaming Assets
     
  34. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,571
    Aaand Bump.

    I'm developing a "code library" to be shared between my projects, and it would be nice to have a checkbox to toggle off entire subfolders of scripts, excluding them from compilation, but without renaming them in any way.

    It is likely possible to include part of the library using package manager, but that's not quite the same thing....
     
    Menion-Leah likes this.
  35. LastChaos

    LastChaos

    Joined:
    Dec 9, 2013
    Posts:
    39
  36. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    96
    How about just a simple right click "Exclude from Build" option?
     
    notunusual, ModLunar and marcb152 like this.
  37. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    What?! Are you mad?? Why would you want that? Why not ask for boxes to tick next to the elements in the whole project's structure and save the setting in profiles (platform, version, etc.) while you're at it?? Do you even realize how efficient and practical this would be for users??

    I wondered if the SBP could be used for something like that but it's focused on asset bundles, and again it's all about scripts, nothing easy to use.
     
    Last edited: May 14, 2022
  38. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    96
    Unity loves a good bloated build
     
  39. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    You mean like this ?
    ExcludeFromBuildTeaser.gif
    It's a WIP project of mine ;-)
     
    Last edited: May 20, 2022
  40. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    96
    That’s so perfect! We need that! And maybe a window with a list of all the excluded assets
     
  41. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    You mean like this :D ?
    ExcludeFromBuildWindow.png

    Asset is in review now (here is the manual):
    Manual: https://kamgam.com/unity/ExcludeFromBuildManual.pdf

    A little teaser on how it works. I am using the fact that files and folders ending with "~" are ignored by unity. So the idea is to hook into the build process, rename them to *~, build and then revert that. It works suprisingly well, though I have not yet tested it on AssetBundles (but it should work there too). Tested in 2019 up to 2022.

    Full disclaimer: it's gonna be a paid asset ($10).
     
    Last edited: May 21, 2022
    ModLunar and Menion-Leah like this.
  42. JGameMaker92

    JGameMaker92

    Joined:
    Oct 15, 2014
    Posts:
    96
    I’ll be getting that as soon as it’s out! My build will look so slimming! :)
     
    _geo__ likes this.
  43. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    Yeaaaah, what should literally be available by default on a multiplatform middleware tool, and that since DAY ONE, is going to be another paid asset.

    Regarding the paid asset, it should come with the possibility to save multiple presets (setups), some of which could also be declared to be the default ones for specific targeted platforms.
    Some setups should allow multitargeting (two platforms or more).
    The selection of the declared/default setups should be obviously automatic depending on the building settings for the current targeted platform.
    A compatibility with gits and cvns would be nice too.
     
    Last edited: May 24, 2022
  44. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    And an important detail I forgot. My build report confirms that the Streaming Assets folder ignores the ~ rule on the folders it contains. The only option I have found is to move the unwanted folders out of the SA main folder before the build.
    So in the context of an automatized build process that's governed by a setup, you would have to temporarily relocate the unwanted folders (checked out of the build process) to a normal folder that won't be included in the compilation. Ergo a temp or cache folder that ends with ~ and which purpose is simply to store the folders that are in the SA folder.
    The process would be:

    1. User ticks a "streamed files" folder that's located in Streaming Assets, to be excluded from the build.
    2. Launch build.
    3. YourPlugin moves (not copies) that folder to a normal Asset folder that ends with ~, like Temp~ or Cache~ located in [YourPlugin/...] main folder.
    4. Build.
    5. Once done, then place that folder back into the Streaming Assets main folder, exactly where it was.
     
    _geo__ likes this.
  45. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    Yes, the groups are meant exactly for these use cases. Each group can have one (or more) build targets (platforms). If there is only one group for the current build platform then that group will be used automatically (it will check before every build). If you have multiple groups for the current platform then the active group (selected via dropdown) will be used. I needed that myself to differentiate between Android builds for GooglePlay vs Amazon.

    Code (CSharp):
    1. Group
    2. + List of ignored files and folders
    3. + Build Target: Android
    4. + Build Target: iOS
    5. ... (by default all platforms are in the 'Default' group)
    Hm interesting thought. It does not yet have an explicit "default" per platform setting. There is a "currently active group" which is used if it contains the current build platform. If not then the first in the list that contains the platform is used (and a warning is displayed). If you switch platforms the the tool will also switch the active group to the first in the list that matches that new build platform.
    A default per platform wouldn't be too hard to add I think. I'll think about it, thx.

    If you want you can already read up on the groups in the manual:
    https://kamgam.com/unity/ExcludeFromBuildManual.pdf

    Things I have used it for (I made this asset initially just for my projects):
    a) Exclude some files from builds on the same target platform (GGP vs AMZN)
    b) Exclude Advertisting SDKs for premium versions. They are such a mess and many of them simply don't care and use a lot of OnPreProcessBuild hooks to add things automatically. Usually that's a good thing but if you just don't want any ads then it becomes tricky. And I really did not want to create a fork for it, because these is nothing to merge back.

    The settings (excluded files) is a really simple ScriptableObject stored under /Asset. So that can be versioned.

    Beyond that I am not sure if any more "compatibility" with GIT is possible. Since Unity does not really have a config file for "exclude from build" I had to use some "hide folder" trickery and that simply does not play well with any vcs.
    If you are concerned about committing the renamed folders by accident then you could add *~ to the ignore file.
    The tool could make a dedicated folder for that and add a .gitignore file there so they would not show up in git. But that would mean a separate implementation for each cvs and honestly, I don't really want to mess with peoples projects that much.

    Things I'd like to add in the future:

    The possibility to not only exclude things but make them swapable. Like having different gradle files or some different c# scripts per group/platform. That would be a handy addition I think. Yet it then requires some extra folders which need to remain hidden and are only added at build time making code completion (IDE integration) tricky. It felt like feature creep. We'll see if the sales justify further development. I ship with full source code (I do it for all my assets). Just in case I get hit by a truck tomorrow (or win the lottery :D)
     
    Last edited: May 24, 2022
  46. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    Oh, thanks for the streaming folders hint. I admit I have not used them much and simply forgot to include them in my tests. I'll add them with a "post launch" update. Feels like a real game launch already :D

    Yes, I am beginning to think that this is something I might have to do. Maybe even put it outside of /Assets just to be extra sure. Though it's a bit cumbersome as I would have to either store (or recreate) the initial folder structure. Right now it renames everything "in-place", which I kinda like.
     
  47. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    Am happy to report that Streaming Assets are now properly* ignored.
    @Starbox : Remind me to send you a voucher once it's out ;-)

    *One caveat though: the build report tools I use do not seem to pick up on the fact that they are excluded. I noticed they simply sum up the file sizes in the Assets/StreamingAssets folder. So these stats are wrong. I still have to find out if that's because they do this after the build or if the Unity Build Report collects this data at the wrong point in time, not sure. If I delete the Assets/StreamingAssets folder after the build then they are gone from the reports. So I think it's the tools doing it and not the report.

    I can already see the complaints coming in that "The tool does not work! My build report proves it". We'll see :D
     
    ModLunar likes this.
  48. Starbox

    Starbox

    Joined:
    Sep 17, 2014
    Posts:
    470
    It might depend on what your report tool... reports. I have observed that with the tool I use, in one of the tool's pages, assets are sorted by type but streamed assets are all lumped together as one type.
     
    _geo__ likes this.
  49. _geo__

    _geo__

    Joined:
    Feb 26, 2014
    Posts:
    1,341
    Yes, I think it really depends on what the specific report tool does. I have now added a popup which let's the user know of the possibility of faulty reports. Hope that's enough to mitigate the issue.

    > "Exclude from build" is now officially released < (got the mail today):
    https://assetstore.unity.com/packages/tools/utilities/exclude-from-build-222791

    Feedback thread:
    https://forum.unity.com/threads/exclude-files-objects-components-from-build.1287671/

    I'd like to offer a free* voucher to anyone who has posted in this thread before. I'd love to get some feedback. If it fails for your use case then I'd like to know. PM me :)

    *Of course I wouldn't be too sad if anyone decides to actually buy it.
     
    mdrunk, JGameMaker92 and Menion-Leah like this.
  50. bleater

    bleater

    Joined:
    Apr 19, 2012
    Posts:
    28
    @_geo__ This asset looks very close to what I need to allow for two different versions of an Android plugin to be used. Does it allow selection of the active configuration based on a Unity preprocessor symbol? Our CI system defines a symbol prior to launching the Unity build and the ability to key off that would be awesome.

    If not, is there some other way the active configuration can be selected programmatically?