Log in or register to post comments

replace 3d model runtime

December 9, 2012 - 10:18am #11

Hi guys 

how can i replace/ swap my 3d model with another 3d model when app is working ?


replace 3d model runtime

December 9, 2012 - 1:12pm #10

Hi, there are many ways of doing that;

one possible way is to attach a script to the AR camera, which do a model swaps based on some input events;

in general, the previous models attached as children of a trackable can be disabled, while the new model can be parented under the same trackable;

This is an example of a script that replaces any pre-existing model with a simple cube (the swap here is activated by a simple touch on the screen, but this is just for simplicity of the example);

you can use this sample as a starting point and elaborate more sophisticated solutions on your own:

public class ModelSwapper : MonoBehaviour {

void Start () {



// Update is called once per frame

void Update () {

if (Input.GetMouseButtonUp(0)) {





private void SwapModel() {

ImageTracker tracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

if (tracker == null) return;


DataSet activeDataSet = tracker.GetActiveDataSet();

if (activeDataSet != null && activeDataSet.GetNumTrackables() > 0) {


DataSetTrackableBehaviour trackable = activeDataSet.GetTrackable(0);

GameObject trackableGameObject = trackable.gameObject;


//disable previous children (old 3d models)

for (int i = 0; i < trackableGameObject.transform.GetChildCount(); i++) {

Transform child = trackableGameObject.transform.GetChild(i);

child.gameObject.active = false;



//Create cube object and parent it to trackable gameObject

GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

cube.transform.parent = trackable.transform;

cube.transform.localPosition = new Vector3(0,0.2f,0);

cube.transform.localRotation = Quaternion.identity;

cube.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);

cube.active = true;





Thank you alessandro But I

December 16, 2012 - 7:47am #9

Thank you alessandro I ll try this in javascript :)

Note that the significant

December 16, 2012 - 9:43am #8

Note that the significant step is the assignment of the obj.transform.parent. You don't need to reference the trackable using the dataset, you can simply obtain it as a gameobject.

Here's how to instantiate custom models in Unity - http://docs.unity3d.com/Documentation/Manual/InstantiatingPrefabs.html

Another approach is to pre-load the models and enable / disable their rendering at runtime. The DefaultTrackableEventHandler demonstrates this approach and shows you how to control their colliders as well.

Error in using this code

January 6, 2013 - 12:45pm #7

Hello David,

Thank you for sharing this code. I want to use this to load multiple models with a gui texture button. I am new to using C# and unable to resolve the errors. I get the following errors when I save your code in a script file. 

Type `ImageTracker' does not contain a definition for `GetActiveDataSet' and no extension method `GetActiveDataSet' of type `ImageTracker' could be found (are you missing a using directive or an assembly reference?)

Type `DataSet' does not contain a definition for `GetNumTrackables' and no extension method `GetNumTrackables' of type `DataSet' could be found (are you missing a using directive or an assembly reference?)

How do I resolve these errors by specifying the right directive? I thought of using DataSetTrackableBehaviour class but I do not know how to do it in C#.  

I created the entire app with separate levels but then it loads very slow each time when changing levels. Hence I am trying to load and unload each model with this method. Other option of preloading all 20+ models at scene startup may slow down scene loading so I can not use it. 

Please guide me. 

Thank you. 

Hi ksb24, the code you are

January 9, 2013 - 11:33am #6

Hi ksb24,

the code you are referring below was working in 1.5, but is now obsolete in 2.0, that's why you get the errors.

You can either try to upgrade it (see migratio guide: https://developer.vuforia.com/resources/dev-guide/migrating-your-unity-project )

or you can more simply try to retrieve a Trackable just by using the Unity function GameObject.Find( "MyTrackableName" );

The specific approach is also depending on your application logic.

I hope this helps.



January 12, 2013 - 2:47pm #5

Thanks for your reply. I will check the migration guide. 

OK, don't hesitate to post

January 13, 2013 - 6:15am #4

OK, don't hesitate to post back here if you have more questions.


Thanks again

January 13, 2013 - 6:32am #3

I am able to replace with setactive(false) old model and instantiate new model. It was really fast and much better than changing scene. My code is similar to the one here. Thank you very much for your support. 

Glad to hear that.

January 13, 2013 - 6:38am #2

Glad to hear that.

replace 3d model runtime

May 9, 2013 - 12:54am #1


How can I do this without using Unity? I mean is it possible to achieve the same from android. I am developing using Eclipse..


Thank You,


Log in or register to post comments