SmartlyDressedGames / Unturned-3.x-Community

Community portion of the Unturned-3.x repo. If you have access to the source code you can find it here:
https://github.com/SmartlyDressedGames/Unturned-3.x/
88 stars 18 forks source link

[PREVIEW] Masterbundles without assets do not load in preview branch. #3864

Closed DanielWillett closed 1 year ago

DanielWillett commented 1 year ago

For a project I'm working on I have a masterbundle that is just treated as a kind of 'Resources' bundle and doesn't actually contain any assets. I've been trying to fix it for a while now and finally figured out why. If there are no assets queued by the reader thread, then the worker's IsWorking property is set to false in AssetWorker.Update while the asset bundle request is still not done, which ends the LoadAssetsFromWorkerThread coroutine before the bundle finishes loading. The bundle never gets removed from pending or loaded into the master bundle list.

I believe an easy fix would just be to make this while (worker.IsWorking || pendingMasterBundles.Count > 0) image

With a test asset: image

With no assets: image

Note how the load start message (which is triggered from a prefix to MasterBundleConfig.StartLoad) gets displayed but the 'load end' message doesn't (triggered from a prefix to MasterBundleConfig.FinishLoad).

Edit: This is the coroutine I'm using to load the bundle image

DiFFoZ commented 1 year ago

Just use the unity API to load asset bundle, https://docs.unity3d.com/ScriptReference/AssetBundle.LoadFromFileAsync.html .

If your bundle is big and want to show the progress bar to the user, then yeah, that may not work for you.

SDGNelson commented 1 year ago

While DiFFoZ is correct that Unity asset bundles can be directly loaded, I agree this would be good to fix in case there is any existing content in the same situation. Thanks for the report!

DanielWillett commented 1 year ago

Works now, thank you.