Log in or register to post comments

assetbundles not working in qcar imagetarget

November 15, 2012 - 11:10am #1

Hi all,
I want to ask about asset bundle unity that use in QCAR,
I've create *.unity3d from the image target as parent and object 3D as child that create as a prefab then build it as *.unity3d

I have try to build the asset bundle to show object 3D and it's success, but when I try in QCAR and Builded it to android, the object 3D didn't appear when the camera face to marker. whereas in unity scene the bundle of imagetarget and object 3D seem normal.

any suggest please,

assetbundles not working in qcar imagetarget

March 18, 2014 - 9:56am #36

hard to tell... both approaches require a bit of coding, as you recognied.

Personally I would maybe oopt for the AssetBundle solution, but note that this feature requires the Unity PRO license (unless Unity has changed the license terms, check in the Unity website to be sure):

See also this:

https://developer.vuforia.com/forum/faq/unity-how-can-i-augment-my-image-target-model

Also, this is just a personal point of view, not an "official" recommendation, so take it with a grain of salt.

assetbundles not working in qcar imagetarget

March 18, 2014 - 9:24am #35

I've looked into the asset bundles approach, which seems to require the work around to be able to include scripts attached to object. However, I've also looked into .OBB expansion files, which requires a work around to make Vuforia Image Targets register and display the models. Which would you say is the best route to take in terms of effectiveness and difficulty?

I'm new to coding so you can understand all this is very daunting to tackle

Thanks in advance

assetbundles not working in qcar imagetarget

March 18, 2014 - 8:44am #34

You could try th workarounds suggested here in that case:

http://answers.unity3d.com/questions/16889/can-asset-bundles-contain-scripts.html

or, as an alternative approach, I would consider splitting the actual 3D model asset from its scripts; 

for example, you could create an Empty gameObject and attach the scripts you need to such object, and then have the 3D Models as dynamic "children" of the parent empty object.

The scripts would also probably need to be adjusted to keep this new structure into account.

 

 

 

 

assetbundles not working in qcar imagetarget

March 18, 2014 - 8:33am #33

What would be the best approach to load 3d models that have scripts attached?

assetbundles not working in qcar imagetarget

March 18, 2014 - 7:33am #32

I believe there might be certain limitations about scripts in Asset Bundles, the details of which can be found in the Unity website:

https://docs.unity3d.com/Documentation/Manual/AssetBundlesIntro.html

 

assetbundles not working in qcar imagetarget

March 18, 2014 - 7:30am #31

what if the 3d model has a script attach to it?

assetbundles not working in qcar imagetarget

March 18, 2014 - 6:40am #30

Hi,

if you have a set of 3D models in your app, chances are that these models are accounting for a bug chunk of your App sze;

if this is the case, the best option I would suggest is to put those 3D models into Aset Bundles and dynamically load the models from the Asset bundles at runtime.

This article provides some useful hints and tips on how to use Asset Bundles with vuforia:

https://developer.vuforia.com/forum/faq/unity-how-can-i-augment-my-image-target-model

 

assetbundles not working in qcar imagetarget

March 18, 2014 - 6:34am #29

Hi everyone, 

I could do with some help on this subject.

I've created an AR app that, when the camera is pointed at any of the trackers, the relevant model appears (much like the other AR apps around). So far I've achieved this and been able to push it to Android devices.

My issue is that it goes over the 50mb limit for the PlayStore. Which direction should I take to reduce my .apk size? Are asset bundles the right way to go with this? And if so, are there any specific differences when using it with Vuforia AR?

Any help will be much appreciated

H

assetbundles not working in qcar imagetarget

December 7, 2012 - 10:27am #28

@elixirbash

1) Yes

2) Yes

My original thoughts were correct. I have to re-load the dataset I'm using once my ImageTarget gets instantiated into the scene.  So, here's my AssetBundle download and QCAR re-init code:

 

IEnumerator doDownload()
    {
        using(WWW www = WWW.LoadFromCacheOrDownload(_bundleLocation,_version))
        {       
            yield return www;
   
            Debug.Log("Download Complete! - " + _bundleLocation);
           
            if (www.error != null)
                throw new Exception("WWW download had an error:" + www.error);
       
            Debug.Log("going to load bundle");
           
            AssetBundle bundle;
           
            try
            {
                bundle = www.assetBundle;
                Debug.Log("name: " + bundle.name);
                Debug.Log("main asset Name: " + bundle.mainAsset.name);
               
                if (AssetName == "")
                    Instantiate(bundle.mainAsset);
                else
                    Instantiate(bundle.Load(AssetName));
               
                // Unload the AssetBundles compressed contents to conserve memory
                bundle.Unload(false);
            }
            catch(Exception e)
            {
                Debug.Log(e.ToString() + " " + e.InnerException.ToString());
            }
        }
       
        LoadDataSet();
    }
   
    private bool LoadDataSet()
    {       
        // Check if the data set exists at the given path.
        
           if (!DataSet.Exists("ConcordAR"))
        {
            return false;
        }

        // Request an ImageTracker instance from the TrackerManager.
   
        ImageTracker imageTracker =
            (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
       
        imageTracker.DeactivateDataSet(imageTracker.GetActiveDataSet());

          // Create a new empty data set.
   
        DataSet dataSet = imageTracker.CreateDataSet();

        // Load the data set from the given path.
   
        if (!dataSet.Load("ConcordAR"))
        {
            return false;
        }

        // (Optional) Activate the data set.
   
        imageTracker.ActivateDataSet(dataSet);

        return true;
    }

assetbundles not working in qcar imagetarget

December 7, 2012 - 2:47am #27

hmm.. this looks like what i had described in my 2nd point.

Answer to your Q:

There is no way you can download a script at runtime for iPhone.

So only option is you shd have the script in the app itself.

if you are planning to have in the app itself,it can be in any folder within Assets.Hence if you load a asset bundle whihc has reference to this script,there will not be any exceptions thrown.

Regards,

Elixir.bash

assetbundles not working in qcar imagetarget

December 7, 2012 - 1:26am #26

I found caution statements at compile time.

"Script attached to 'ARCamera' in scene 'Assets/Scenes/QCAR-Hardwaremovie.unity' is missing or no valid script is attached.

UnityEditor.HostView:OnGUI()"

and,

Mono Behaviour file is not like I am inside.

Is it possible to download this file?

Also, you should put in which folder?

 

Regards,

secimo

assetbundles not working in qcar imagetarget

December 6, 2012 - 10:33pm #25

NT7Games,

Chk these out..

1)did you assign the trackable name to the image target prefab when you took a build of the asset bundle?

and are you using the dataset that contains the same trackable?

 

2)is any trackable eventhandler attached to the prefab?

if so is that eventhandler present in the asset folder of the app too?(because even if you attach the script while taking a  asset bundle,what gets attached to the bundle is ONLY the reference of the script,but NOT the actual script ).So this means you shd have the same script in the Asset folder.

It ll be even better if you can post your logs

 

 

assetbundles not working in qcar imagetarget

December 6, 2012 - 10:32pm #24

NT7Games,

Chk these out..

1)did you assign the trackable name to the image target prefab when you took a build of the asset bundle?

and are you using the dataset that contains the same trackable?

 

2)is any trackable eventhandler attached to the prefab?

if so is that eventhandler present in the asset folder of the app too?(because even if you attach the script while taking a  asset bundle,what gets attached to the bundle is ONLY the reference of the script,but NOT the actual script ).So this means you shd have the same script in the Asset folder.

It ll be even better if you can post your logs

 

 

assetbundles not working in qcar imagetarget

December 6, 2012 - 5:10pm #23

I could use a little help as I'm in a similar boat:  Here's what I've got:

1) Scene starts. Scene consists of an ARCamera Prefab.  Dataset "A" is loaded (my dataset .dat and .xml lives on my device and is NOT downloaded at runtime)

2) I download an AssetBundle from the web and instantiate the bundle's mainAsset into my scene.  The assetbundle consists of an ImageTarget Prefab meant to track an item from Dataset "A", and a 3D model to render. I believe that QCAR "knows" about the ImageTarget because the OnTrackingLost() method gets fired when I instantiate the ImageTarget prefab from my bundle.

3) Here's my problem... DataSet "A" is definitely loaded, and the ImageTarget is most likely in the scene (since it's Start() and OnTrackingLost() methods have been called, I make this assumption).  However, when I point my camera at the physical target, nothing happens! No OnTrackingFound or anything like that!

Do I need to re-initialize the ImageTracker or something like that if I add ImageTargets to the active scene AFTER QCAR has been initialized / enabled?

This was a killer thread and very helpful thus far but I just need a little push to the finish line and I'll be forever grateful :)

EDIT:  Everything works as expected in the editor - this problem ONLY exists on the iOS device. Probably super-important that I mention that :)

assetbundles not working in qcar imagetarget

December 6, 2012 - 8:14am #22

Thanks for sharing!

N

assetbundles not working in qcar imagetarget

December 5, 2012 - 5:39pm #21

Of course I can,

Below is my mistakes and cause of that I could not instantiate my ImageTrackables.

1) must not instantiate before using swappable datasets(https://ar.qualcomm.at/sdk/ios) because I used the next script:

if(TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) == null){

Debug.Log("generates Image Tracker.");

TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);

}

2) 'persistentPath' for download .dat and .xml to my local diretory was not responsible in Unity Editor. But I noticed when I built App to Xcode(my App for iOS), 'persistentPath' shows me correct path in Xcode console.

 

And below is great key for me to succeed, the keys are by moderator's:

3) Unity's WWW class is used to download .dat file and xml file, and .unitypackage is distinct from AssetBundle. So I have to hink about they each are different stuff. To instantiate ImageTrackables just need .dat and .xml, datasets. My Asset Budle contains only child objects. If I need script, attach with AddComponent() in App.

4) I thought about 'dataSetPath' and 'dataSet' especially and budle 'LoadDataSet' class and 'AttachContentToTrackables' class into single class.

I am not good at English, but if anyone can refer to this experience, I'm very glad. 

Thanks

assetbundles not working in qcar imagetarget

December 5, 2012 - 2:51am #20

Great to hear Eugene2763 !

If you can please just sumarise what you did so it can also benefit the community here :)

many thanks,

Nalin

assetbundles not working in qcar imagetarget

December 4, 2012 - 10:14pm #19

Hi NalinS & DavidBeard,

I succeeded swappable dataset from my server just now.

Thank you for your continuous support.

I will share this understanding in Japanese Unity user community.

Thanks so much.

Sincerely,

 

K

assetbundles not working in qcar imagetarget

December 4, 2012 - 3:14am #18

I think this came up before here:

https://ar.qualcomm.at/content/please-provide-sample-swapping-dataset-unity3d

and the key points are below:

Unitypackages are distinct from Asset Bundles. Where a *.unitypackage can bundle a diversity of file types as an archive, Asset Bundles are intended for binary assets and compile these into a proprietary format recognized by Unity's scene loader.

We do not recommend trying to put datasets in asset bundles because the Unity packager will most likely reject it.

Therefore it is best to download and instantiate the datasets within a .unitypackage - you'll need to download these to the local directory, quite possibly you may also need to extract the .dat and .xml files and use STORAGE_ABSOLUTE.

If you search the forums you may find others who have done something similar.

HTH

N

assetbundles not working in qcar imagetarget

December 4, 2012 - 2:01am #17

I took a mistake dataSetPath, but I could adjust the path in iOS.

But my ImageTargets AssetBundle from server have not been recognized in my App.

I am using Swappable Dataset script and refer from Stones&Chips, tarmac example.

Maybe, I fail to instantiate Trackables. I discovered that the trackables with AssetBundle from server appear when I select AR camera or the trackables in Unity Editor.(Vice versa, they do not appear until I select one of them)

If I can let the trackables the situation, it will be able to be recognized in my App.

Why are my trackables AssetBundle from server transparent at first on Play? What can I do this situation.

Thanks in advance.

assetbundles not working in qcar imagetarget

December 3, 2012 - 11:07am #16

Are you using Unity Pro or Basic?

..as asset bundles are Pro only.

N

assetbundles not working in qcar imagetarget

November 30, 2012 - 2:24am #15

Hi NalinS, thank you for reply,

But I have not done well swappable dataset... I attatched the scripts but it's error.

error log: Data set http://myURL/myassetbundle.unity3d does not exist.

I tried WWW, instanciated new WWW() and WWW.LoadFromCacheOrDownload() but the both cannot load my URL.

I'm very sorry for my poor understanding, but I want to succeed swappable dataset and use asset bundles on my vuforia app.

I couldn't ge information about this in Japanese Unity Community.

Please help me.

 

assetbundles not working in qcar imagetarget

November 28, 2012 - 4:01am #14

Hi Eugene2763

Swappable datasets are covered in the SDK Guide > Getting Started -Unity Extension > Step 3 Matersing Advanced Topics > Swappable datasets

There you should find details covering loading/activating/destroying datasets.

HTH

N

 

assetbundles not working in qcar imagetarget

November 28, 2012 - 1:33am #13

Is there anyone can use Swappable Dataset or Unity's Asset Bundle in Vuforia yet?

I really want to know how it's possible.

If I can select dataset & image target of ImageTarget Prefab, it is possible that my ARCamera recognizes ImageTargets, I think.

It is not enough only AddComponent.

Please help me.

assetbundles not working in qcar imagetarget

November 26, 2012 - 11:54pm #12

Hi David,

The requirement is we dynamically load dataset and asset bundles.

We have a need to start animations of the models that are dynamically loaded in OnTrackingFound() in TrackableEventHandler.cs

This is one requirement where we need change in script.

And there is also a need where user can interact with the 3d model thru touch interface and dosome interactive actions

assetbundles not working in qcar imagetarget

November 26, 2012 - 6:55pm #11

To my knowledge, there is no way to update Unity scripts in this way, and alternative techniques employing assembly loading or relflection are specifically prohibited for iOS due to Apple policy. 

What would you like to be able to accomplish specifically? 

assetbundles not working in qcar imagetarget

November 23, 2012 - 4:13am #10

Thanks for the reply,

but looks like it wont work for iPhones .

So there is no option to dynamically update default trackable event handler at all?

Is this possible without Asset Bundles?

So if im using unity for my AR app then i will never be able to update the content of the scripts?

please suggest /throw some light on how this could be done..

Thank you

assetbundles not working in qcar imagetarget

November 23, 2012 - 2:40am #9

Hi elixirbash,

Strictly this is a Unity issue.

Asset bundles cannot contain scripts.

http://answers.unity3d.com/questions/16889/can-asset-bundles-contain-scripts.html

http://forum.unity3d.com/threads/29641-Build-asset-bundle-.unity3d?p=232756

However "Angry Ant" from Unity has a workaround described here:

http://angryant.com/2010/01/05/downloading-the-hydra/

and also here:  http://answers.unity3d.com/questions/9688/dynamically-loading-scripts.html

...which may or may not work for you.

HTH

N

 

assetbundles not working in qcar imagetarget

November 22, 2012 - 1:18am #8

Hi all,

what would be the best practise to attach scripts as a part of the bundle.

As im aware of the fact that scripts could be a part of asset bundles as compiles files.

I 'd like to know what would be the best approach to dynamically update the eventhandler.cs sscript.

 

Elixir.bash

assetbundles not working in qcar imagetarget

November 20, 2012 - 10:41am #7

Yes I've got it. Give me a couple of days to look into this.

assetbundles not working in qcar imagetarget

November 20, 2012 - 3:40am #6

Hi David,

I've sent you a message of this topic,

please help,

assetbundles not working in qcar imagetarget

November 19, 2012 - 1:00pm #5

Can one of your send me your project and I'll see if I can generate a sample.

assetbundles not working in qcar imagetarget

November 18, 2012 - 7:18pm #4

I'm also not able to track my Trackables, tried to attach script with AddComponent("SCRIPT_NAME") after instance my trackables.

But ImageTargetBehavior script is not loaded my AR camera.

Instance my prefab, but no dataset & image target.

And I tried to use scripts in 'Swapable Dataset' from official documentation.

But I cannnot understand those script what object or script I should attach or add them.

If anyone can use those script and success instance assetbundle from web, could you give me the sample attachment image or sample code?

Thx in advance.

assetbundles not working in qcar imagetarget

November 16, 2012 - 11:31am #3

Thanks for your reply and suggest David,

but I still confuse when you said Asset Bundles can't contain scripts,

I've try to debug assetbundle sample (http://unity3d.com/support/resources/example-projects/assetbundles) on android and it's success, but from your sample code, it seem not bundle the cube and other object 3D using asset bundle concept,

I hope the assetbundle result (*.unity3d) that contain marker and the object 3D saved in  SDcard android, so if I want to add marker and the object 3D as child I just to update the *.unity3d without reistall the Augmented reality APK.

 

assetbundles not working in qcar imagetarget

November 15, 2012 - 12:20pm #2

Asset Bundles can't contain scripts, so it's likely these are being stripped from your ImageTarget if you are attempting to bundle this prefab. If you want to be able to load targets at runtime, you can do this using the Dataset. See the Getting Started guide's Advanced Topics section on Swappable Datasets.

 

e.g.

// Add Trackable event handler and content (cubes) to the Trackables.

private void AttachContentToTrackables(DataSet dataSet)
{
    // Get the number of Trackables defined in the data set.
    
    int numTrackables = dataSet.GetNumTrackables();

    // Loop over all Trackables.
    
    for (int i = 0; i < numTrackables; ++i)
    {
        DataSetTrackableBehaviour dstb = dataSet.GetTrackable(i);
        GameObject go = dstb.gameObject;

        // Add a Trackable event handler to the Trackable. // This Behaviour handles Trackable lost/found callbacks.
        
        go.AddComponent<DefaultTrackableEventHandler>();

        // Create a cube object.
        
        GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        // Attach the cube to the Trackable and make sure it has a proper size.
        
        cube.transform.parent = dstb.transform;
        cube.transform.localScale = new Vector3(0.7f, 0.7f, 0.7f);
        cube.transform.localPosition = new Vector3(0.0f, 0.35f, 0.0f);
        cube.transform.localRotation = Quaternion.identity;
        cube.active = true;
        dstb.gameObject.active = true;
    }
}
Log in or register to post comments