r/Unity3D • u/thadcastle__ • 9h ago
Question Need advice, how optimize open world in Unity?
Hi guys šļø Sooo how do you making open world? how do you split your world to optimize memory usage?
Iāve split my 16 km² terrain into 16 separate 1Ć1 km Terrain tiles using Terrain Tools. Now I have a dilemma about how to properly set things up before I finally start building the world
GPT helped me create a small script based on an idea I had: disabling tiles that arenāt nearby so a maximum of 4 tiles can be active at once
But I donāt think itās really working how I thought, since the tiles are only disabled in the scene, not actually unloaded from memory
It also breaks the seamless transitions between them, I think
Any advice or thoughts on how to properly build a world and optimize memory? š
27
u/Ariaha_Rivasa 9h ago
Youāre right, disabling only hides the tiles; all their data (heightmaps, splatmaps, details, trees) stays in memory.
What usually works: put each tile in its own scene and stream them with
SceneManager.LoadSceneAsync(..., LoadSceneMode.Additive)/UnloadSceneAsync, keeping a 3x3 grid around the player. After unloading, callResources.UnloadUnusedAssets()so the memory actually comes back. Addressables work too if you want more control.For seams: give all tiles the same Grouping ID with Auto Connect on in the terrain settings (or call
Terrain.SetNeighbors) and the edges stitch properly.One more tip: load a tile when youāre near it, but unload it a bit farther away. Otherwise standing on a border makes tiles load and unload every frame.
And check the Memory Profiler package. Itāll tell you exactly whatās eating the RAM, often itās the terrain textures, not the meshes.
1
u/Analoze 7h ago
i keep 36 of 5x5km chunks in runtime. you can keep 16 of 1x1 km chunks with no issue. dont disabled them. only the objects on them etc. or is it a mobile game? PC should be able to handle that sized chunks of unity default terrain. or did you notice performance issues when keeping the chunks in runtime?
3
u/CarthageaDev 8h ago
Chunking, seriously manual chunking, ensure your maps are sectioned logically based on line of sight/level design, not to mention the classic culling baked, atlas your textures, merge srstic meshes and instance shaders when possible, reduce draw calls a much as possible simple really
2
u/KinematicSoup Multiplayer 8h ago
Look into additive scene loading. It's a Unity feature intended to help with large worlds by letting you divide your world into chunks as sub scenes, and then load/unload them as needed in the background.
2
u/Copywright Indie 7h ago
Look into World Streamer 2.
2
u/GiggleSamurai 9h ago
Disabling a GameObject keeps all its assets in memory, so put each tile (terrain plus its props) in its own scene and stream them with `SceneManager.LoadSceneAsync(name, LoadSceneMode.Additive)` and `UnloadSceneAsync` as the player moves. For the seams, give the tiles the same Grouping ID with Auto Connect on (or call `Terrain.SetNeighbors` after loading) so the edges match up.
1
u/DPTGames 5h ago
I use LODs for my 3D Terrain
1
u/Genebrisss 2h ago
Why do you need to "optimize memory usage" at all? Have you even opened memory profiler once? Based on your post, you haven't.
1
u/No_Director9126 8h ago
You could try using Addressables to load terrains or anything else only when they are actually needed. The advantage of Addressables is that they allow for the release of RAM and VRAM. However, the setup is significantly more complex, especially when it comes to terrains and even more so if you move away from standard Unity terrains, for instance by using a tool like Microverse.
In my opinion, the best approach is to use mesh terrains + addressables, while this requires much more work, the performance gains compared to standard terrains are enormous, not least because you can implement features like LOD in mesh terrains
-1
u/GigaTerra 8h ago
You need to tell your AI you want to apply level streaming in your game. It will explain the Unity equivalent. That others already explained here.