Ok I am creating a menu item to help me create patches for my MMO.
Here is what I have:
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;
class CreatePatch
{
[MenuItem("MMOInteractive/Create Patch")]
static void Execute()
{
Object[] bundle = new Object[10];
int num = 0;
foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
{
if (!(o is GameObject)) continue;
bundle[num] = (GameObject)o;
num++;
}
string bundleName = "Patch0.1";
string path = AssetbundlePath + bundleName + ".assetbundle";
BuildPipeline.BuildAssetBundle(null, bundle, path, BuildAssetBundleOptions.CollectDependencies);
}
public void test()
{
}
public static string AssetbundlePath
{
get { return "Assets" + Path.DirectorySeparatorChar + "assetbundles" + Path.DirectorySeparatorChar; }
}
}
Now for my client what is the most basic code needed in order to load a Object from the Asset Bundle?
WWW code that loads the asset bundle and then the AssetBundle.Load function to instantiate it then.
But keep in mind that you can’t patch files with asset bundles. if the same asset is in the runtime twice at the same time the asset bundle that tried to load it will bomb out with an exception
Is it possible to load asset bundles from a website? So like on my website (http://www.riseofheroesmmo.com) have a folder called assets located at for example http://www.riseofheroesmmo.com/assets and then store the bundles there and have the server send the client a list of the bundles. Then to change a model recreate the asset bundle and replace the one on the website with the new updated one or to add a whole new one with different models just upload it to the website and let the server know about the new bundle.
How are asset bundles for Performance in large projects? Will I be able to use Asset Bundles for all my assets with little hit on the performance or will they drain the system after a while?
the performance isn’t affected by asset bundles, after they are loaded they behave as if they were part of the game.
but they might add a RAM usage overhead that could or could not affect you.
Assets bundles are useless for large projects. You have to write down your own resouce manager (loader/unloader).
Don’t see how an own resource manager fights against asset bundles as they are nothing else but external resource folders.
Also they are the only way to load anything asyncronous at all
I want to have two separate programs (games) that load the same asset bundle.
However, if an asset has a script associated with it, there seems to be no alternative
to distributing the script wit both games. This further implies that if I want to alter the
script in anyway, I have to redistribute both games. This is problematic even for 2
games, but when it becomes a nightmare when there are several games, and even
worse still when the games are really worlds built by separate developers, and all they
really want to do is use the same simple asset that happens to have a script or two.
Is there ANY way to address this problem that I may have missed in all my searching??
Thanks very much.
–rmbuinty
You could wait until you Instantiate the object to add the scripts to it. So then in the Asset Bundle the script wouldn’t be attached to it.
Yes, but in that case, the script still has to be distributed with all games that use the asset,
whereas if the script is attached to the asset bundle, I can fix the script in just one place
and redistribute just the asset bundle, not all the games.
No you can not.
Compiled code assemblies are never in the asset bundle, they are always in the application.
So you can freely assign it in the bundle but the script file itself must be part of all applications.
Asset Bundles, as their name implies (ASSET) transport only assets, that would be audio asset, texture asset, mesh asset, prefab and text asset
I have decided to re-open this thread since the problem of asset bundles not supporting scripts is driving my team nuts.
First, the above logic says that asset bundles are only for assets and even puts the word asset in caps (ASSET). However,
assets have components. By the above logic, no component should travel with its asset in a bundle, because only assets
(ASSET) are bundled. Since scripts are documented as components, they should be treated as first class citizens as
much as any other component, in this regard.
I understand that there is concern over security regarding malicious scripts. It would be nice if a developer could have an
option of accepting bundled scripts from trusted sites. An all-or-nothing approach is very restrictive.
I really feel like a whiner complaining about this issue but it is causing us much grief. It would be great if some compromise
could be provided where one could choose to accept scripts or not based on a flag.
Thanks for listening. And please help.
–ralph
There is no concern.
Its plain simply not possible through unity code thats meant to reside as regular code to use and test in the editor.
“should” is something about which the compiler, which checks for typesafeness etc at compile time in the editor does really not give a damn about. Code that would be in asset bundles would just be that, plain text with no meaning at all, as the player does not compile any code etc.
But I think the problem here is that you are mixing some stuff.
Yeah Scripts are components, but
- Components are not assets, they are components. no idea where you are missconcluding that functionality has anything to do with media
- They are only components when compiled, otherwise they are just code. This compilation takes place when you use the build player function.
- Components as per above definition can be present in asset bundles, no present. Any prefab can have many preconfigured scripts attached. Code per above definition can not be present in asset bundles as the compilation happens in the editor, not in the player as such code makes totally no sense in the player, it would be worthless text with no execution meaning.
The mentions on security etc sounds like you additionally mixed the reasons why plugins don’t exist on the webplayer with other aspects and platforms, where they have no relevance to.
Would like to actually see comments from people who have done large projects. I haven’t, so I won’t comment and assume asset bundles are good or bad. My instinct is they’re good and will be improved in the next patch.
They are indeed good if you keep their limitations in the back of your head. That means:
- The same asset must never be in 2 asset bundles or your build + asset bundle
- Only assets (audio, texture, meshes, movies, text assets) and prefabs can go there, not code as thats no asset
Nowhere in my write-up did I once say that a component was an asset. And yet you immediately imply in
point number one that I did. That is a misconclusion on your part. And your comment that functionality has
nothing to do with media is itself open to mis-interpretation. The fact that media is not equivalent to functionality
misses the mark completely by ignoring the fact that there is a very close relationship between the two.
In any case, I seem to be full of mis-conclusions. At this unity3d web page:
The following comment occurs:
AssetBundles can contain any asset found in the project folder.
One confusing part is that scripts seem to play a dual role. In one case they appear as assets (in source form)
in the Projects folder. Thus, one could easily be lead to mis-conclusions based on the above documentation.
In the second case, they are components associated with any object to which they are attached. Presumably
this is a reference to a compiled version of the source. The presumption that source code can not re-compiled
dynamically at a later time and place would come as quite a shock to a number of researchers in language
theory and implementation that I know. Perhaps it true that Unity can not do it. I would not debate that point
even for a nanosecond, and would agree that that essentially concludes the argument against me.
We do not do game development per se.
I love the Unity product and use it in multiple courses and research projects for educational purposes. Further,
I have always found the support to be superb and responses from employees and fellow users to be cordial
and helpful. I guess life changes as we get older and we can’t expect things to stay the same forever.
rmbunity
I agree that the Asset Bundle documentation wouldn’t be hurt to point out in more detail what gets included and what not and what applies to which platforms on the limitation end.
The code topic has been a thing of recurring questions and shocks since asset bundles were initially introduced for example, so nothing that only affects you or a handfull of people.
In that case if you aren’t after a game or generally have likely more “tech savy” devs and don’t need full realtime performance, you are in the lucky position that there are ways:
- You can use the runtime compiler and then use reflection to get to your stuff - not a way for various reasons
- AngryAnt in 2009 - 2010 wrote a great blog post on his page on how to dynamically load external assemblies (code compiled to managed libraries) and work with them through reflection if I recall right. This essentially allows you to load assemblies from the outside. Its naturally more troublesome to work with reflection than just with them as if they were classes inside the project but thats essentially a thing you can’t get around (at least to my knowledge) due to the when its compiled and when it becomes part of the app. Essentially this is the all managed counterpart of how c / c++ work with dynamic libraries too.
You still can’t include them in asset bundles, BUT you can keep them seperate and load them as you need them.
We are aware of the Angry Ant ‘solution’ but were hoping for a Unity-developed method.
We have a large team of computer scientists, engineers, physicians, and graduate students
at two of the largest universities in TN. We are developing projects that assist children
with neurological disease. We had chosen Unity as our centerpiece for development. I am
going to ask all of them to read this page and offer comments to me.
In any case, I am going to regard this thread as re-closed and hope that I have no further
need to turn to the forums for help. If we need to use the forum perhaps I will have one of
them to do it. I am quite frankly burned out.