Hello,
I need to create an application that loads a number of bundles.
Each of them is composed of the graphics (models, materials, textures) and logic (scripts) with references, within the bundle, to gameobject / materials / textures.
The problem is not loading the bundles at runtime, but load and properly handle the specific logic of a given bundle.
What I am searching for is a good way to load, at runtime, some new enemy type with some custom behaviour classes.
Using asset bundle I can load asset at runtime, but is I am not wrong I can’t load scripts.
Any script (even shaders) should be present inside the main application. There’s no way to load scripts via asset bundles. Scripts are not considered “assets”.
If you are loading assets bundles using some scripts/shaders, those should be already loaded by the main app or else you get errors.
I guess this works in some systems (Window?). But I wouldn’t personally do it… how much code variation do you have so you should load it separately?
Shame that Unity cannot load and execute arbitrary code like Flash does (Flash can load another Flash and run it’s code). However, not having this possibility is better for security.
I am still in design phase and I don’t know exaclty how much variation …you totally right load and execute arbitrary code is a usefull feature that allow you to keep smaller the webplayer without useless code.
Just for information, why you don’t like dll import?
I’m posting information in related threads of our community, to clarify how Shaders and Asset Bundles work together, and how to avoid some conflicts. The shader’s code is included with the asset bundle, whenever shaders are directly referenced as parameters in BuildPipeline.BuildAssetBundle(), or indirectly with option BuildAssetBundleOptions.CollectDependencies. This could cause a problem if you use BuildAssetBundle alone to create several asset bundles, since referenced shaders will be included in every generated bundle. There could be conflicts, i.e. when you mix different versions of a shader, so you will have to rebuild all your bundles for any modification. This also increases the size of bundles. To avoid these problems you can use BuildPipeline.PushAssetDependencies() to separate shaders in a single bundle, and that will allow you to update the shader bundle only. We are adding a page to the manual with more information on this topic and examples of the workflow to build a shader bundle.