- Home /
How to Load a scene from addressable on the preloading scene without changing scenes?,How do I preload an addressable scene without changing the scene?
I want to preload the scene from the addressables and keep it without changing scenes. Addressables.LoadSceneAsync("sceneName"); does load but it changes the scenes as soon as it finishes. I don't want that. I just want to load it on the preloading scene, then use that to load the scene when I press the button for it.
Please help, it is very urgent. Best Regards.,I want to preload a scene that has been marked as addressable without it changing scene. Maybe be saving on some type of variable. And than referencing to that scene whenever I want to get to the scene.
I want to achieve something like this in the preloader. But I don't want to change the scene right away. Addressables.LoadSceneAsync("sceneName");
Answer by wigglypuffs · Dec 25, 2019 at 11:29 AM
public string NextScene = "MainMenu";
public AssetReference Level;
long downloadSize;
AsyncOperationHandle asyncHandle;
void Awake()
{
if (Level.RuntimeKeyIsValid() Addressables.GetDownloadSizeAsync(Level.RuntimeKey).Completed += GetDownloadSize_Completed;
}
void GetDownloadSize_Completed(AsyncOperationHandle<long> obj)
{
if (obj.IsValid())
{
downloadSize = obj.Result;
asyncHandle = Addressables.DownloadDependanciesAsync(Level.RuntimeKey);
asyncHandle.Completed += Preloader_Completed;
}
}
void Preloader_Completed(AsyncOperationHandle obj)
{
if (obj.IsValid())
{
if (obj.Result != null) SceneManager.LoadScene(NextScene, LoadSceneMode.Single);
}
}
void Update()
{
// Do your progress bar updates here... etc
}
Note: Download size can be 0 if the content is already cached so don't rely on the size. The size can be useful in determining how far along you are, for example you can display in a text box:
if (asyncHandle.IsValid())
status.text = $"{asyncHandle.PercentComplete * downloadSize} / {downloadSize}";
Though, I've found it not to be entirely accurate. You might want to remap the range or something, in my case I found that 0.18 to 0.48 percent is the true range. I'm not entirely certain why.
Answer by laurentlavigne · Aug 04, 2020 at 03:32 AM
var loadAsync = Addressables.LoadSceneAsync("sceneName", activateOnLoad=true);
then when you're ready to activate:
loadAsync.Result.Activate();
Your answer
Follow this Question
Related Questions
CheckConsistency: GameObject does not reference component Animator. Fixing. 0 Answers
Load a scene from AssetBundle 0 Answers
Addressables - Use Asset Database (faster) - Not loading assets within a folder 1 Answer
Does the Singleton GameObject need to be in all scenes where i need to access it? 2 Answers