Speed up preloads using unity-scene-repacker#157
Conversation
|
Draft because the version of https://github.com/jakobhellermann/unity-scene-repacker used is not yet released and currently contains some hardcoded data for Hollow Knight I want to remove first. |
b947780 to
cfa8860
Compare
|
Test build: MAPI-windows.zip |
|
Practically speaking, I think having this as a mapi global setting is bad since the majority of users will see no benefits from the feature that way. I would propose the following approach instead:
|
|
I think having an opt out ( setting it to enabled by default) will be good enough for players wanting to kill switch it. for mods wanting to use scene hooks, they should be able to indicate somehow that they care to hook into some scenes and only those should be loaded in that case. |
Yes, it makes sense to have this enabled my default. I mostly did it this way first in case we wanted to do some testing before rolling it out, in case there are any issues that come up. E.g., I haven't tested this on macOS, and I wonder if the native dependency immediately works on apple silicon.
Since we know what mods request scene hooks, we could also do that automatically. Use |
By extracting `DoPreloadRepackedScenes` into a separate method, that just passes the scenePrefix to `DoPreloadScenes`.
previously this was hardcoded in the unityscenerepacker dll
|
Have other people tried this much? The pr itself looks fine to me, though if you could get UnitySceneRepacker.cs using the typical C# style that'd be nice. Sorry for taking a while, slipped my mind. There's a few very minor nits I'd like to mess with if you don't mind me doing that as well. |
i'm using this api version and so far i've not seen anything wrong in the |
No worries, and I don't mind. I don't have a lot of time to work on this anyways for the next month, so I'm in no rush to get this merged. |
Currently preloading loads the entire scene at startup, which is usually the slowest part of startup.
unity-scene-repacker lets us repack the game's scenes into AssetBundles which can be loaded instead.
This PR introduces a
PreloadModeglobalsetting, with the following modes:full-scene: the current behaviourrepack-scene: repacks the scenes into anAssetBundlecontaining the exact referenced scenes, but filtered to only relevant objects. The preloading code stays pretty much the samerepack-assets: repacks the scenes into anAssetBundlethat contains the game objects separately, which can then be spawned using `bundle.LoadAsset("SceneName/path/to/object.prefab"). For compatibility with the current API, every object still gets spawned in the beginning and handed off to the mods.Some rough benchmarking with a few mods enabled:
20sfull-scene9srepack-scene5srepack-assetsHowever, only full-scene and repack-scene modes support
sceneHooks.In this PR:
unityscenerepacker.dll(orlibunityscenerepacker.{so,dylib}on linux/macOS)$(SolutionDir)from csproj f9f50d0 this enableddotnet build Assembly-CSharp --runtime win-x64which is required to copy the native dependencies.<CopyDir>csproj variable which you can set to your game to automatically copy files on build, simplifying the build -> run -> edit cycle (I can move this to another PR or delete this if y'all don't like this)