Assetbundles <- Something I don't get.

I made a couple of examples with assetbundles, where a cube object has a texture assigned to it + a script to make it rotate over time.

so 1 cube, 1 texture and my rotate.js script.

These things are then turned into an assetbundle (scripts in assetbundle example) and I load the assetbundle from the assetbundle demo application.

Now I discovered that SCRIPTS don’t seem to load from inside an assetbundle.

However, when I put the script (called it rotate.js) in the project it works.

Now this confuses me.

First thing I have understood is that scripts should stay in the project on compilation of the main unity3d webplayer or standalone.

But… why exactly?
If I’m not mistaken, then unity3d automatically knows which assets are needed by a program and includes only those things from the project which are effectively used.

Unity3d doesn’t know what script my assetbundle wil need? So how can it work? And where is the javascript saved then? In the assetbundle or in the main webplayer/standalone.

This can be a big difference, because if you have 1 main movie and 100 assetbundles with scripts, then it would mean 1 of 2 scenarios

  1. All scripts are compiled and stored inside the main webplayer/standalone and not in the assetbundles (this would mean that the main webplayer/standalone would get quite bigger, because 100 assetbundles with for example each 10 scripts doing stuff = 1000 scripts in the main webplayer/standalone.

  2. OR… The scripts are NOT put in the main application/webplayer, but just some kind of reference to them and the actualy scripts are effectively saved within the assetbundles themselves, which results in the size of the scripts being dispersed over the different assetbundles and a relatively smaller main webplayer/standalone.

Any extra information about that would be greatly appreciated.

Regards, Thanks,

Bart

All scripts in your project are included in your build whether or not they are used. Unity is unable to do effective build-time checking about which scripts are used. This is because you can do things like:

var base:String = "Enemy";

function Start()
{
   // add script Enemy1 to Enemy10 on object
   gameObject.AddComponent(base + Random.Range(1, 10));
}

Or other scenarios where you are dynamically adding components (maybe even based on user input, etc). Personally we never do patterns like this in production, but some people probably are!

OK, understood, but does that mean that all these scripts are then saved in the main webplayer/standalone and in the assetbundles there is only a reference to them ?

I suppose that not all these scripts are loaded in memory and active then, but just when they are effectively referenced in an assetbundle and used on a GO ?

Regards,

Bart

Yes and yes.

Well that makes them quite usable :slight_smile: