Static mesh smooth, safe Unload ? 2018.1

I’m writing level-streaming system. Loading with

Application.backgroundLoadingPriority = low 

is pretty smooth.

But

Resources.UnloadUnusedAssets() function is only way to unload everything SAFELY.

I’ve pretty large world, with lots of game object, LOD-groups cross-referenced materials and textures. Thats why :


  • Resources.UnloadAsset(something) can’t be used with static. It’s is ok with textures, acceptable, but if you try to unload Chunk A, and its static combined mesh, which consists of A and B chunk objects, objects in Chunk B will disappear.
  • Mesh.Combine() is bad idea cause of it breaks LOD-Group work, Isn’t it?

Questions:

  1. Is there way to combine static meshes ONLY INSIDE additively loaded scene? or
  2. is there way to SEPARATE static meshes “per-object” (runtime?) ?
  3. is there any way to TIME SLICE Resources.UnloadUnusedAssets()? AsyncOperation typical way doesn’t help
  4. Alternatives, to unload static meshes from memory?

Well, when you say “static” i guess you mean statically batched objects, right? It highly depends how you made those objects to participate in static batching. Note that once several objects are batched together you can’t seperate them. The only way would be to destroy all objects that have been batched together and recreate those you want to keep. This of course isn’t very useful.

However you said that you have “chunks” you want to manage. What you can do is to manually batch the objects you want to be combined at runtime using the StaticBatchingUtility. Of course if you load permade levels as “chunks” those shouldn’t be marked as static. When you call StaticBatchingUtility.Combine it should have a similar effect as if the object was marked as static. However it should only combine the child objects / the objects you specify. Though i can’t guarantee that it will work. You may want to do some tests.

Obviously the performance gain when you create smaller batching groups would be less than when having the whole scene batch together. Also calling Combine manually may decrease your “smooth transition” performance.

.

If the loading / unloading is too heavy you may want to split your world into several smaller scenes / chunks. Thanks to the multi-scene edit feature it should be easy to seperate a single scene into multiple.

Just turn off static batching in settings

Performance impact wasn’t so big. It was replaced with dynamic batching / GPU-Instancing


And no need to unload meshes. No generated chunks, only original meshes, which are lightweight and don’t dublicate in memory after reload chunk.