Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Headless Server - Don't include Textures in build

Discussion in 'Multiplayer' started by Sasasoft, Sep 11, 2020.

  1. Sasasoft

    Sasasoft

    Joined:
    Nov 6, 2016
    Posts:
    7
    Hello Unity Forum!

    I've building a Unity game with multiplayer and I'm using the Server Build option to create a Headless server from the project as well. My problem is that the size of the Server Build is the same as the size of a normal non-server Windows x64 build of the game. I'm pretty sure, that (among a lots of other things) it's because of the huge textures I'm using.

    How could I exclude or remove these textures (and maybe other not needed assets) from the Server Build?

    Or maybe decrease their resolution to a negligable size? I can't see how I could do that without affecting other Standalone builds.

    Thanks in advance!

    Best Regards,
    Dávid Szabó
     
  2. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    Same issue for us ... Currently I only know of two options:
    1. Replace texture assets (and other big ones that aren't needed, like A/V files) with "empty" ones (e.g. 1*1 px)
    2. Update the asset importers to limit the import sizes, e.g. on textures set the max resolution to 32*32 px
    Do that before building for headless and then revert to the regular ones for the normal build.

    Of course both options do reimport those assets (once when reducing, once for reverting afterwards) which is why I haven't actually added those to our build setup yet as this would increase build times by about another 2 hours just for reimporting stuff.

    Variant 1 can easily be achieved with this asset: https://assetstore.unity.com/packages/tools/utilities/headless-builder-108317
    Of course that does not help with the additional time required :(
     
    Sasasoft likes this.
  3. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    You could remove the assets from the Asset folder and then use a symlink (system link) to make them available in your game, when you make a server build you just remove the symlink and non of them will be included.
     
  4. Alloc

    Alloc

    Joined:
    Jun 5, 2013
    Posts:
    241
    But also cause a lot of missing links in assets. On textures that won't hurt a lot but still not be nice. On other asset types it might cause actual issues though, so would not recommend that. Also it would still require reimporting those textures when going back to a normal build.
     
  5. FakeByte

    FakeByte

    Joined:
    Dec 8, 2015
    Posts:
    147
    What I like to do is to set a global define in the player settings, then I use something like #if SERVER_BUILD in my code, if you just leave asset references that are unsued in your server build then thats just wasted memory in my opinion.
     
  6. Sasasoft

    Sasasoft

    Joined:
    Nov 6, 2016
    Posts:
    7
    Thank You for the suggestions! So far I fear that there are only "hacky" ways to solve this problem.

    I'm wondering if we could control the build process with some editor scripts. Like, #if UNITY_SERVER ... //Magically exclude the textures from the build assets for the current build ... #endif
    Any experiences in this area?
     
  7. Sasasoft

    Sasasoft

    Joined:
    Nov 6, 2016
    Posts:
    7
    Or maybe some configuration possibilities with the new Addressables?
     
  8. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    692
    Any Unity dev opinions on this? It makes iterating really hard because I have to copy an almost 2 GB (and growing) chunk of data to the server every time. :/

    Any hacky solution us client devs could do would be super slow from what I am seeing, whereas I think an option to just not include textures would work super well if that existed on the Unity side.
     
  9. Sasasoft

    Sasasoft

    Joined:
    Nov 6, 2016
    Posts:
    7
    I'm started using the Headless Builder plugin that is recommended by Alloc. After a few trials of different configuration settings, it shrinked my server build from 7.3 gb to 566 mb (300 mb zipped for PlayFab). The build is longer because it backups all your textures, overwrite them with dummies, builds, then restores Your textures. I don't know how long my SSD will hold under this stress, but it does the job for now.

    In official Unity feature would be much better for this, thats for sure.
     
  10. OnatKorucu

    OnatKorucu

    Joined:
    Apr 18, 2018
    Posts:
    8
    [Conditional()] annotation let's you ignore the callers of chosen function when building. So if you write 2 functions, IncludeTextures() and ExcludeTextures() and call them conditionally based on the defined parameters, you can do it.