Search Unity

Strip or unload built-in textures for headless server build

Discussion in 'Multiplayer' started by keedav, Aug 15, 2019.

  1. keedav

    keedav

    Joined:
    Mar 3, 2013
    Posts:
    4
    Hello everyone,

    I'm currently experimenting with Unity as a dedicated game server. For each room I'm planning to spawn a new process, and I need to reduce memory footprint as much as possible.
    However I can't seem to unload some built in textures, namely:
    UnityNHxRoughness (32.3 KB)
    UnityHalo (4.3 KB)
    UnityAttenuation (2.3 KB)
    UnityGrayscaleRamp (2.3 KB)
    etc...

    Jegyzet 2019-08-15 152838.jpg

    As you can see in the attached memory snapshot, almost 1/3 of the total memory are used up by built-in textures. My question, how to I reduce the memory footprint even more? How to strip these textures? What modules are using it?

    I'm using Unity 2019.2.0f1, IL2CPP on Windows, disabled almost all built-in packages.
     

    Attached Files:

    Last edited: Aug 15, 2019
    Opeth001 likes this.
  2. keedav

    keedav

    Joined:
    Mar 3, 2013
    Posts:
    4
    Well almost one week of trying out different methods I'm still stuck. However I have found out some useful things for others who may stumble into this problem.

    After examining the build asset files, I found out that these textures are not packaged there during the build.

    The only reference for the UnityNHxRoughness texture this is in
    UnityStandardBRDF.cginc
    shader include file
    Code (CSharp):
    1. half LUT_RANGE = 16.0; // must match range in NHxRoughness() function in GeneratedTextures.cpp
    That means these textures are in fact generated when the player starts.

    I have tried to forcefully destroy or unload the textures from memory with this
    Code (CSharp):
    1. var objs = Resources.FindObjectsOfTypeAll<Texture2D>();
    2.         foreach (var obj in objs)
    3.             Object.Destroy(obj);
    But it does not work. For all built-in textures I'm getting this message
    Destroying object "UnityNHxRoughness" is not allowed at this time.


    So the most minimal memory I have managed to achieve is around 15MB with every Unity modules disabled. It would be great if someone from Unity would have a look at this, but in the mean time I think I submit a bug report.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You could ask the developer of the Headless Builder asset on the Asset Store if his/her asset includes stripping these textures. Often asset developers are more than happy to discuss how they have solved certain issues, even if you have no intention of making a purchase.
     
    keedav likes this.
  4. bluescrn

    bluescrn

    Joined:
    Feb 25, 2013
    Posts:
    642
    I really wouldn't worry about a little 32KB texture, given how large a minimal Unity project can be. That really sounds like premature/misdirected optimization?

    Do you really need a process per 'room'? (and what is a room? - a group of players in a lobby/game, or a physical room in an MMO-ish game?). Can you run N of them on a single server instance?
     
    Joe-Censored likes this.
  5. keedav

    keedav

    Joined:
    Mar 3, 2013
    Posts:
    4
    The goal of this experiment is to see how feasible is to spawn one Unity instance for every room. What I meant with "room" is a short game session with 4 players. For example as in Diablo.

    Probably the solution for such a problem is what you have just described. But I had to measure what is the absolute minimum memory consumption for a headless server.
     
    T-Zee likes this.