Assetbundle *.asset

I think you just change the type within the angle brackets:

FooBar foobarAsset = myLoadedAssetBundle.LoadAsset<FooBar>(assetname);

… assuming your asset type is a FooBar

To the extent possible, I recommend NOT using asset bundles this way. Instead, if possible just put an entire scene into the asset bundle and load it all at once, and have your own resource locator strategy inside it.

Then you just additively load the scene and get what you need. It’s very clean compared to digging around in the bundle with code, which now you have to maintain and debug.

Additive scene loading is one possible solution:

A multi-scene loader thingy:

My typical Scene Loader:

Other notes on additive scene loading:

Timing of scene loading:

Also, if something exists only in one scene, DO NOT MAKE A PREFAB out of it. It’s a waste of time and needlessly splits your work between two files, the prefab and the scene, leading to many possible errors and edge cases.

Two similar examples of checking if everything is ready to go:

1 Like