Log in or register to post comments

Child a GameObject to ImageTarget

July 18, 2012 - 10:22pm #1

Basically what I am doing is downloading the assetBundle which is basically a prefab containing .fbx and some behaviour references...one of which is a drag behaviour that i've attached to a prefab.What I want is to limit the touch and drag behaviour only on the ImageTarget.Since ImageTarget itself is a prefab(obviously) I am unable to instantiate the assetBundle as a child of ImageTarget.

 

Is it even possible (limiting the transform positions of downloaded assetBundle to the local positions of ImageTarget)?? Or am I stuck on wrong implementation??

 

sorry if the question seems noob...

thanks in advance.

Child a GameObject to ImageTarget

November 13, 2012 - 10:04pm #10

Hey guys,

Thanks for your valuable replies.

That was helpful.

 

Child a GameObject to ImageTarget

November 12, 2012 - 6:25am #9

What I do is have a universal Game Object (called Universal for ease) and an added script that loads an asset bundle into memory and then any script can find Universal and get a reference to that asset bundle. I dont have any problems with that approach besides calling unloadUnusedAssets after a while to free up some memory.

Child a GameObject to ImageTarget

November 10, 2012 - 4:48pm #8

If you're certain that the assets will eventually be used in the scene, you could try loading the AssetBundle after the scene is initialized by QCARBehaviour.Start(). 

Child a GameObject to ImageTarget

November 10, 2012 - 12:14am #7

destroying and then again instantiating an assetBundle is really expensive....What i did was to load the assetbundle only first time the tracker is found and then after it if the tracking is lost i make the gameObject inactive or make its local scale to vector3(0,0,0) just to make it invisible....

 

 

Child a GameObject to ImageTarget

November 7, 2012 - 11:38pm #6

raigex wrote:

I actually do something similar(the adding a child to image target at runtime)

in TrackableEventHandler.cs (or your own derivative)

create a private gameObjecte named model(or watever you want)

 

then in onTrackingFound()

a simple boolean

if(model == null)

(load asset bundle somehow and return it)

then check if assetbundle contains what you want it to (I use all my model using their trackable name)

then model = Instantiate(bundle.Load(mTrackableBehaviour.TrackableName, typeof(GameObject)))as GameObject;

(add material if youwant )

then

mdel.transform.parent = this.transform (this makes the new model a child of the image target)

 

 

Hi,

this is what im doing currently,

but loading asset bundle on OnTrackingFound is a very time expensive operation rite.

I thought of loading the assetbundle in Start/awake function but that will overload the RAM usage.

What could be the optimum way to load an asset bundle based on tracking found.

Please throw some light on this

 

Thank you

Elixir.Bash

Child a GameObject to ImageTarget

July 20, 2012 - 12:37am #5

Thank You all! worked like a charm.

So basically what i was missing was to assign the assetBundle and the ImageTarget a GameObject.

The only problem is that by doing this I'll have to "Find" a specific name each time from a bundle.

 

Anyways thanks again for being so helpful.

Child a GameObject to ImageTarget

July 19, 2012 - 7:30am #4

Yes you would instantiate these objects independently and then assign them to the parent.

Here's an example..

using UnityEngine;
using System.Collections;

public class LoadAssetBundleCube : MonoBehaviour {

public WWW www;
public string url = "Cube.unity3d";
public string resourcePath = "Cube";
public int guiOffset = 20;
public AssetBundle assetBundle;
public Object instanced;

private GameObject go;
private int progress;

public LoadAssetBundleCube()
{
}

// Use this for initialization
IEnumerator Start()
{
// Start a download of the given URL
www = WWW.LoadFromCacheOrDownload(url, 1);

// Wait for download to complete
yield return www;

// Load and retrieve the AssetBundle
assetBundle = www.assetBundle;

// Load the GameObject
//go = assetBundle.Load("mainAsset", typeof(GameObject)) as GameObject;
go = (GameObject)assetBundle.mainAsset;

// Instantiate the GameObject
Instantiate(go);


GameObject goImageTarget = GameObject.Find("ImageTarget");
GameObject goCube = GameObject.Find("Cube(Clone)");
goCube.transform.parent = goImageTarget.transform;
}

// Update is called once per frame
void OnGUI()
{
GUILayout.Space(guiOffset);
progress = (int)(www.progress * 100);
GUILayout.Label("download: " + progress + "%");
}
}


* keep in mind that AssetBundles for mobile need to be built specifically for the target platform.

Child a GameObject to ImageTarget

July 19, 2012 - 6:17am #3

I actually do something similar(the adding a child to image target at runtime)

in TrackableEventHandler.cs (or your own derivative)

create a private gameObjecte named model(or watever you want)

 

then in onTrackingFound()

a simple boolean

if(model == null)

(load asset bundle somehow and return it)

then check if assetbundle contains what you want it to (I use all my model using their trackable name)

then model = Instantiate(bundle.Load(mTrackableBehaviour.TrackableName, typeof(GameObject)))as GameObject;

(add material if youwant )

then

mdel.transform.parent = this.transform (this makes the new model a child of the image target)

 

Child a GameObject to ImageTarget

July 19, 2012 - 6:08am #2

Hi udaan

ImageTargets can have children as that's how the augmentations actually appear, though I have not tried adding a child at runtime, nor downloading an asset bundle to try and add this.

What errors are you seeing?  Have you tried adding a prefab (not downloaded) at run-time?

N

Log in or register to post comments