Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am executing the following method from the Unity Start() method:
private void GetFiles()
List<string> files = new List<string>();
EnumerateFiles(baseDir, ref files);
foreach (string assetBundleName in files)
assetBundle = AssetBundle.LoadFromFile(assetBundleName);
prefabs.Add(assetBundleName, assetBundle.GetAllAssetNames().ToList().Where(s => s.ToUpper().EndsWith(".PREFAB")).ToList());
catch
if (assetBundle != null) { assetBundle.Unload(true); }
I am trying to enumerate through a bunch of asset bundles and look for prefabs. I have no issue getting the list of asset bundles. However, to determine the prefabs inside I need to load the asset bundle and then use something like GetAllAssetNames() to determine the contents. In my case, I look for the asset name ending in Prefab to determine prefabs. The code works fine as long as none of the asset bundles are corrupt.
However, if a asset bundle is corrupt, the application throws a, seemingly uncatchable, exception and ends execution. I have placed the asset bundle load and the GetAllAssetNames() call in a try/catch structure to try to catch such an error and just continue with the next asset bundle but the try/catch does not seem to be able to catch the error.
Any idea how I can catch such an error to prevent the application from crashing?
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.