I'm trying to load scenes from an AssetBundle that is stored on the device locally, but when I try to load the scene, the loading process goes well but when the scene ends loading, I get warnings and errors like:
The referenced script (Unknown) on this Behaviour is missing!
The referenced script (Unknown) on this Behaviour is missing!
The referenced script (Unknown) on this Behaviour is missing!
The referenced script (Unknown) on this Behaviour is missing!
The referenced script (Unknown) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'EventSystem') is missing!
The referenced script on this Behaviour (Game Object 'Load Slider') is missing!
The referenced script on this Behaviour (Game Object 'Main Camera') is missing!
The referenced script on this Behaviour (Game Object 'Canvas') is missing!`
And I get some errors:
A scripted object (probably UnityEngine.InputSystem.InputActionReference?) has a different serialization layout when loading. (Read 44 bytes but expected 96 bytes)
A scripted object (probably UnityEngine.Rendering.PostProcessing.PostProcessResources?) has a different serialization layout when loading. (Read 52 bytes but expected 1380 bytes)
A scripted object (probably UnityEngine.Rendering.PostProcessing.PostProcessProfile?) has a different serialization layout when loading. (Read 48 bytes but expected 76 bytes)
I tried to change the way in which I create the AssetBundles and checked if there was a problem with the AssetBundle but I didn't get any result from it.
I finally managed to fix this issue. To fix this, the solution was to unload the AssetBundle using unload(false)
after the scene is loaded.
void LoadScene(string path, AssetBundle bundle = null)
{
IEnumerator Load()
{
loadPanel.SetActive(true);
loadPanelText.text = "Loading level..."; //TODO: Translate
AsyncOperation op = SceneManager.LoadSceneAsync(path, LoadSceneMode.Single);
while (!op.isDone)
{
float progress = Mathf.Clamp01(op.progress / .9f);
sliderProgress.value = progress;
loadProgressText.text = $"{progress * 100}%";
yield return null;
}
bundle?.Unload(false);
}
StartCoroutine(Load());
}