Load Scene from dynamic location at runtime
I am trying to load a scene at runtime after downloading it from the Steam Workshop. Modders can make a scene and upload it to the workshop. The player downloads all of the scenes, and they get placed wherever they installed Steam.
It seems addressables are supposed to solve this, but the documentation is severely lacking. How can I use addressables to load a scene from a dynamic location at runtime? I only have knowledge of the location of the scene at runtime, as they can download a new map at any time during play.
Answer by ambid17 · Sep 20, 2020 at 12:18 AM
The solution for those looking for it:
public static string LoadSceneFromBundle(string path)
{
DirectoryInfo fileInfo = new DirectoryInfo(path);
string scenePath = fileInfo.EnumerateFiles().First().FullName;
AssetBundle bundle = GetAssetBundle(scenePath);
if (bundle == null)
{
Debug.LogError($"failed to load asset bundle {scenePath}");
return string.Empty;
}
string[] scenes = bundle.GetAllScenePaths();
Debug.Log($"loading bundle from scenepath: {scenes[0]}");
string scene = Path.GetFileNameWithoutExtension(scenes[0]);
return scene;
}
Your answer
Follow this Question
Related Questions
use AssetBundle.LoadAssetAsync in editor is about 10 times slower on windows than on ios devices 1 Answer
Error loading assetbundles on ios in background,Error loading assetbundles on ios in background 0 Answers
Problem with Asset Bundles in Unity 2020.3.30f1 1 Answer
Why does the AssetBundle needs the assets to be present in the folder? 0 Answers
Addressables build failing due to Lua scripts and then for an unknown reason 0 Answers