Hi everybody.
I absolutely need to import a collada (.dae) asset dynamically through a script.
Dynamically because I’m building an application which models a mesh accordingly to some user input, so I cannot recompile in Unity.
I tried to use AssetBundles but I’m quite a newbie in Unity, maybe I’m missing some important point.
Here my few lines of code, the script is attached to a empty game object in unity.
Basically I want to import the collada asset in the path and put the object “monkey” inside the scene.
WWW urlExternalAsset = new WWW("file://D:/Unity/monkey.dae");
GameObject go;
void Start () {
AssetBundle bundle = urlExternalAsset.assetBundle;
go = bundle.Load("monkey", typeof(GameObject)) as GameObject;
Instantiate(go);
}
Thank you for your help.
I’m doing a project with my university and this part is fundametal for me;)
Luca
To use AssetBundles you need to:
1 Build an AssetBundle that includes the Monkey Asset. Note that this is not the collada file, but the Asset that you see in the Project folder. The instructions to do that you can find in these places:
http://unity3d.com/support/documentation/Manual/AssetBundles
http://unity3d.com/support/documentation/ScriptReference/BuildPipeline.BuildAssetBundle.html
*Note: The file extension for the AssetBundle is not important.
2 Put that AssetBundle file in a location where you will load it from:
D:/Unity/monkey.assetbundle
3 Download the AssetBundle using the WWW class:
IEnumerator Start (){
WWW urlExternalAsset = new WWW("file://D:/Unity/monkey.assetbundle");
yield return www;
// 4. Retrieve the AssetBundle from the WWW object:
AssetBundle bundle = urlExternalAsset.assetBundle;
// 5. Load the Mokey GameObject from the AssetBundle:
GameObject go = bundle.Load("monkey", typeof(GameObject)) as GameObject;
// 6. Instantiate the GameObject:
Instantiate(go);
}
Enjoy!
Ok.
I think that what I’ve done is just what you described in point 3.
I can’t understand the meaning of what is described in the first 2 points…what does build the asset bundle mean? Considering that I’m creating the .dae file runtime I need to load it also runtime in a previously built file. I can’t launch the unity editor, I can just use scripts.
I will try to summarize of does my pipeline work
-
I have a C# program continuosly getting infos from a Kinect
-
On the other side, I have a unity .exe (which I already created), that shows a 3d avatar.
-
After an acquisition phase I stop getting data from the Kinect and I run the previously built Unity .exe, which should use the data acquired runtime to build the 3d world. I did it successfully with textures…now I want to apply the same procedure also to meshes. → That’s why I need to import collada .dae dynamically.
Do you think this is possible with AssetBundles? What could use if not?
Thank you so much.
Luca