Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to stop Unity Terrain from creating grass texture atlases on awake?

Discussion in 'World Building' started by Lynxbird, Oct 30, 2023.

  1. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    Unity Terrains are creating atlas textures for grass details like this in RAM and I need to stop that:



    Problem is that I am streaming world from addressables and every time I load terrain async, terrain on awake blocks the main thread and freezes the game with TerrainData.AwakeFromLoad.

    After some debugging I found that it happens only when I have grass on terrain, it seems Unity is creating those huge textures (42MB) for every terrain and that those are freezing the game.

    Those huge atlases are problems for RAM and problem for performance as they are not run async.

    Can I tell Unity terrain to stop doing that? Or is there a way to tell it to not do it on main thread? Any idea helps.


    I tried using asset bundles, same issue.
     
  2. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    Or even better if I could make TerrainData.AwakeFromLoad stop from blocking the main thread after TerrainData is loaded async?
     
  3. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    I built a custom made world over the period of 3 years out of 300 unique terrains and now I want to stream terrains through addressables.

    Problem is that every time I load TerrainData game freezes for 0.2 seconds.


    After I load terrain it will freeze main thread with TerrainData.AwakeFromLoad call. And soon after will freeze it a bit more with Loading.LockPersistentManager call for terrain culling.


    After some investigation I noticed that freeze is much longer for terrains which have more grass on it, as Unity is creating terrain atlas in memory for each terrain like this:





    They say https://issuetracker.unity3d.com/is...-after-loading-a-terrain-from-an-asset-bundle they resolved bug like that in 2023.1 but it is not case for me as I am having problems with grass. I tried 2023.1 and it has same issue.

    What I tried so far:

    - Load and instantiate terrain async from addressable
    - Load disabled terrain addressable
    - Load only terrain data async without instantiating (freeze is still there on load)
    - Tried using resources folder for terrains
    - Tried using loading it through asset bundles
    - Tried Unitu 2020.3, 2021.3, 2022.3 and latest 2023.1
    - Tried packing addressable data uncompressed and grass textures uncompressed
    - Tried running load code on parallel threads
    - Tried loading all terrains and holding them in memory (no spikes after loading but for 300 terrains it is 12GB RAM because each created mini atlas so I am trying to avoid having them all in RAM)


    My only remaining idea is to remove grass variation from all the 300 terrains, which sadness me as I painted a beautiful world. Before trying that I am looking for any other ideas or info.
     
  4. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    I am offering a free copy of game to anyone who could help me!! :--)
    Unity experts help!!
     
  5. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,013
    What are you using for rendering vegetation items on the terrain? Are you using Unity stock tools or a 3rd party asset? I would suggest building your own vegetation rendering, so you have full control over that. Or find a 3rd party one that already does what you need. But I would not recommend using Unity's built in vegetation rendering with anything large or complex.
     
  6. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,013
    Another idea is to double check your asset bundle settings. Make sure CRC checking is disabled.
     
  7. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    I am using the default Unity terrain grass. I've already hand-painted an entire world comprised of 250 terrains, each one 300x300 in size.
    Switching to a 3rd-party asset would cost me months of work to repaint details, and there is no guarantee it would scale much better.
    I was hoping to make the Unity default terrain behave as expected.
     
  8. ShilohGames

    ShilohGames

    Joined:
    Mar 24, 2014
    Posts:
    3,013
    Unfortunately, it is not realistic to expect Unity's built in vegetation rendering to scale like that. Unity's built in solution is fine for simple small stuff, but not big complex things.

    You might not need to change all of your hand painted information. There are some 3rd party assets that take the existing vegetation data from the terrains and render it differently.
     
  9. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    You know what, I reduced the size of all my textures to 256/512 resolution. In addition to that, I followed your advice and disabled CRC. The lag is still present in the editor, but once I built the game, this time, the terrain loading lag decreased significantly.

    It seems like the combination of those two remedies the issue to a bearable degree.

    I believe you deserve a free copy of the game. The release is in 30 days, and I'll have some free keys, one of which is reserved for you. I will contact you to ask where to send it, and do you want it. :D

    Thank you very much for your time and effort.
     
    ShilohGames likes this.
  10. TerraUnity

    TerraUnity

    Joined:
    Aug 3, 2012
    Posts:
    1,244
    @Lynxbird As others suggested, your best bet is to use 3rd party solutions for vegetation placement and especially grass layers with dense settings since stock Unity grass system in terrain is very limited and heavy.

    In the meantime we just released TerraLand 4 which is a world streaming solution on top of Addressables and we made a technical demo out of it to stream huge (2500km2) area of a real-world location with dense vegetation via our Runtime Spawners in runtime so its data don't have to be baked to stream. Check it out here: https://terraunity.com/community/to...tic-nexus-terraland-4-streaming-demo-windows/

    Also as you said, there are always small to big lags and hiccups using Addressables in the Unity editor but once you build your scene, there will be a smooth experience in runtime.
     
  11. Lynxbird

    Lynxbird

    Joined:
    Aug 19, 2018
    Posts:
    17
    Fix was to disable CRC, lower terrain precision, lower grass texture sizes to not use more than what is needed and removed unused grass from terrains. Now it works fine.