I'm currently trying to set up my project to allow users to download mini games post release. Todo this I am trying to use asset bundles to facilitate this, one containing the new games scene and one containing the assets and DLLs for the scripts required. The problem I am having is that when I load the scene or a prefab from the bundle all the attached scripts are still there but a warning says "the associated script can not be loaded. please fix any compile errors and assign a valid script". Is there something obvious that I am missing or do asset bundles not work this way and I'm going to have to rebuild my scene on load?
You can't have the scripts in the asset bundles assigned as references from GameObjects like you normally would. You can only access scripts from asset bundles by loading them with reflection. Then you can programmatically attach them to GameObjects, etc. from there (for example, load the assembly, find your Type, then use AddComponent() on a GameObject with your new loaded type).
See http://docs.unity3d.com/Manual/scriptsinassetbundles.html.
But even if you were to overcome these hurdles, it won't work on Windows Phone and it's against the terms of service of Apple's store, so ...
Related
I'm currently looking to implement On Demand Resource on my project.
I already use Asset Bundle, but I'd want some of them to be On Demand Resource.
I found this page https://docs.unity3d.com/2019.4/Documentation/Manual/AppThinning.html
And there is things that I'm not sure to understand.
So I need to create a script BuildiOSAssetBundles to tell Unity which Asset Bundle I want to use as ODR.
But I'm confuse by this line :
new UnityEditor.iOS.Resource( "bundle", "Assets/Bundles/bundle.unity3d" ).AddOnDemandResourceTags("bundle"),
I didn't found the documentation of "Unity.iOS.Resource" object, and I'm a bit confused about the path I should give.
For exemple, I have a bundle named "foo/bar", which is composed of 3 scenes : "foo_level1", "foo_level2", and "foo_level3", let's say that theses scenes are located in a folder named "Assets/Foo/Scenes".
How do i do to tell Unity that this bundle should be a On Demand Resource ?
Plus, I have a lot of bundle similar to "foo/bar" (let's say 50). Do I have to register them one by one in that script ? Or is there a way to "mark" every bundle starting with "foo/" as ODR ? (Is there a GUI ?)
When I build my assets bundles from the GUI, the path I'm using is "AssetBundles/iOS". May be I should use that in the path ?
I have a mobile project which displays various AR experiences to the user via a mobile application. This application is made in Unity.
Alongside this Unity project we have a second project that stores asset bundles exclusively. Each AR experience is a prefab marked with a unique asset bundle name. These bundles are stored online and downloaded into the main mobile application when relevant. We're having issues with having these bundles correctly update, when changing things on the prefab such as scale or rotation they aren't reflected in the rebuilt asset bundle.
Here's a look at the process we're using for rebuilding assets, It's only a simple script.
[MenuItem("Spiff/Build AssetBundles")]
static void BuildAllAssetBundles()
{
// BuildPlatformBundles(BuildTarget.iOS);
BuildPlatformBundles(BuildTarget.Android);
}
static void BuildPlatformBundles(BuildTarget platform)
{
// We convert the passed platform enum to a string.
string platformFolder = platform.ToString();
string assetBundleDirectory = "Assets/AssetBundles/" + platformFolder;
// Build our bundles out to the relevent platform specific folder.
if (!AssetDatabase.IsValidFolder(assetBundleDirectory))
{
AssetDatabase.CreateFolder("Assets/AssetBundles/", platformFolder);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, platform);
}
Currently we use 'BuildAssetBundleOptions.None' We've also tried the ForceRebuild flag but this has no effect. Am I correct in assuming that Unity has some sort of internal cache it keeps for assets bundles? If so can we clear this somehow so I can ensure 100% that the bundle I am building is going to be the most up to date based on the prefab tagged with it?
Loaded Assetbundles are indeed cached, and will remain so until AssetBundle.Unload() has been called to free up all memory accociated with the asset.
After the asset has been unloaded a newer version of the assetbundle can be downnloaded and instantiated with the new values (Assuming the file downloaded has all the updated information), else it will load the data from cache if available.
On a side note: It seems like you're still using the old assetbundle pipeline. Unity has a plugin tool that makes the assetbundle workflow considerably easier called the assetbundle browser found here. It comes with a way easier UI for building bundles and inspecting bundles, open source and a very customisable pipeline. It may be worth checking out.
Like remy_rm mentioned, do give the Unity Asset Bundle Browser tool a try. It gives more control over what assets are in the bundle.
Your problem can be solved if you ensure two things:
1- When you make changes to a prefab and create a new bundle, is it indeed created with the said changes? (again using the tool would make checking this easier)
2- The bundles you are downloading in the main application are the new ones and not the old cached ones. In Unity Webgl for instance, you need to clear the browser cache to be 100% sure that the application downloads the new asset bundles and doesn't use the old ones in browser cache.
I'd like to load "dynamic" assets (in particular, FBX files) that are located outside of a "Resources" folder so that the user can add/remove/modify files with no need to re-build the project.
To make those files easily accessible for the user in different kinds of devices (target platforms are desktop/android/ios), it seems reasonable to use either Application.persistentDataPath or Application.streamingAssetsPath.
Now the problem is: How do I load them (as proper Unity objects) ?
This obviously can't be done via Resources.Load() as they are outside a "Resources" folder.
Using WWW, retrieving the files should be easy and it could actually work for some types of files (e.g. textures, see http://docs.unity3d.com/ScriptReference/WWW-texture.html) but I cannot see a way to load something else.
The idea is that I'd like to be able to use those loaded objects like so:
(GameObject) Instantiate(loadedObject, new Vector3(0, 0, 0), Quaternion.identity);
I would really appreciate your help (preferrably with a solution that does not require a "pro license").
I know two options that you can try to use in this case:
Build an asset bundle for each dynamic asset you want to load, but this seems not really what you desire, because the user still have to use Unity3d to generate the asset bundle.
Use an custom 3d model loader, like described in this post, seems the best fit for your case.
I'm starting learn unity not long ago. Now, I have issues. When I build a game, I don't want build all assets in project. I want download some assets when Client after install game (Ex : first load Splashscreen). I tried to search and found WWW.LoadFromCacheOrDownload. I don't sure it correct!.
Can you give me solutions or keyword?
Thank you very much.
You are on correct road. But i think you need to google a bit deeply the keyword and you would have reached the "Asset Bundles".
Asset Bundle Defination
Scripting Asset bundles
Asset Bundle management
Asset Bundle detail description
I did asset bundle usage quite some time ago so i might miss something while explaining this.
First you need to build the resources which you will be required.(Each platform has different builds so you need to keep that also in mind)
You will need a script to download and cache the asset bundle from the net.
WWW.LoadFromCacheOrDownload
After caching comes the part of loading and unloading asset bundle from cache/resources. Also for every update we pushed we allowed application to check for any asset bundles were available so that it could fetch and use it.
I think there are some more helper scripts for the asset bundles and tutorials to go with on the net as I had used a script to generate asset bundles
to modify it.
Here is unity asset store Example and scripts for asset bundles
So basically it will be a long solution to implement but it is worth every time you spend.
Hope this helps.
Edit : Here is script I had used to create asset bundles. Unifycommunity Asset bundle builder Link
I want to using the Unity3d framework for a project in which I have create a walkthrough. But the client want it to be dynamic.
We would be getting the final fbx file from 3DMax which when added to a particular folder a walkthrough should be created automatically. I went through the help files on Unity3D site but did not find any documentation as to how use the Unity3D framework programmatically.
Can anyone please let me know how can it be done? Even if link is provided for the resource it would help us.
Unity 3D has a built in way to load models at runtime, but this should be done using a Resources folder (Resources.Load()) or using a Asset Bundles (AssetBundle.Load()) as described here: http://docs.unity3d.com/Documentation/Manual/LoadingResourcesatRuntime.html
These two methods are performed inside the Unity editor and your need is load any arbitrary 3D model file at runtime, for this case you will need a plugin. The only one that I know is ObjReader.