I want to create a lot of detail in my game but I don’t want to kill the frame rate tracking all the models and movements (like all the grass). Will loading them in pieces save the frame rate or will constantly loading and unloading models with every step negate any benefits of loading in pieces? I want to only load what the player will see at that moment and nothing else until the player either moves the camera or walks. I also want to know if loading a scene on Unity uses the gpu or the cpu?
When your game scene becomes so large that you run into performance and/or memory problems, then it can make sense to divide your world into separate scenes and only load those around the player. By loading a scene with
LoadSceneMode.Additive you can load the content of a scene into a current scene, so both scenes coexist at the same time. And when you use
SceneManager.LoadSceneAsync, then the loading will happen on a background thread, so the player won't notice any hiccups while scenes are being loaded. The drawback is that under some circumstances, the player might move so fast that they manage to move into a scene before a scene is loaded, which can cause a myriad of problems (like falling through the not-yet-spawned floor or walking through a not-yet-spawned wall). So it can make sense to keep the
AsyncOperation object returned by that method and check whether it has loaded.
So for loading a scene in the background:
var loadOperation = SceneManager.LoadSceneAsync(newScene, LoadSceneMode.Additive);
When you want to unload the content of a scene you loaded additively but don't need anymore, then you use
SceneManager.UnloadSceneAsync. You might also want to use the option
UnloadSceneOptions.UnloadAllEmbeddedSceneObjects. This option ensures that any assets which are no longer needed will also be removed from memory:
You most likely will not run into that problem. If you're doing a personal project, my gut feeling is that if you are having performance problems in your level then you're probably facing more issues with LOD optimization or bad shaders/lighting. Unity should be plenty powerful for what you're envisioning.
However, It definitely depends on just how visually involved you're talking about.If you DO wind up seeing dropped frames, here are methods I would suggest:
1.) Cull the backsides of your geometry. HL2 is a good example of this. Look at their maps and it looks like they're all cardboard cutouts. But in game, they felt like whole city blocks even back in the early 2000s.
2.) Use LODs to lower the detail of out of focus or far away items. This is the Unity Manual page for the LOD Component: https://docs.unity3d.com/Manual/LevelOfDetail.html
3.) After that, I would recommend something akin to Unreal's level streaming. I'll admit, I put this one last because I haven't done this directly in Unity. But the premise is that instead of trying to dynamically cull and render objects as the player's FOV changes, use triggers to dynamically load/unload whole sections of the map. If they go down the elevator, you can cull the floor they just left for example.
Edit: Came across this post today, seemed relevant: http://victor.madtriangles.com/code%20experiment/2020/06/12/post-ue4-perf_guide.html