Hello,
I created several scene asset bundles that are stored on a remote server and loaded at run time, but it seems when i add a script to a gameobject in the scene asset bundle, the scene is loaded, but the script isnt loaded, and i get an error that the script is missing when the scene is loaded into the browser.
I added a script because i need to set the camera far clipping distance for each scene separately to speed up rendering because it was running slow in certain browsers.
Does this mean WebGL scene asset bundles cant have scripts attached to gameObjects? is that like a security thing? Maybe im doing something wrong?
Thanks
from the manual: “If you want to include code in your AssetBundles that can be executed in your application it needs to be pre-compiled into an assembly and loaded using the Mono Reflection class (Note: Reflection is not available on platforms that use AOT compilation, such as iOS).”
This limitation is also true for Unity WebGL and all platforms using IL2CPP. So, you can’t have scripts in asset bundles.
Ok, the thing is that each scene bundle needs a little initialization after its loaded that is specific to that scene, so what would be the method to accomplish that since i cant put a script in the scene bundle?
Thanks!
Actually, I think the original question is relating to components. If you have a custom component in an asset bundle which isn’t in your main project, I’ve ran into the same ‘error’.
There’s two fixes to this:
1- Disable code stripping, all your classes will be embedded and work, or
2- Have a small “make everything work” scene in your build, which has a copy of all the scripts you’re using.
I believe you can also direct code stripping with an XML file, but it sounded like a lot of manual work. 