Topic locked

How to get current target name in unity

July 15, 2013 - 12:11am #1

HI,

How to get current image target name and size  in unity .

Please help me.

How to get current target name in unity

March 5, 2015 - 2:18am #13

This thread is very old (the last post before yours is dated2013) and it refers to an old version of Vuforia (2.x). The API has changed a little bit in newer versions; the TrackableType type no longer exists in Vuforia 3.x and 4.x.

In Vuforia 3.0 and 4.0, you can check if a Trackable is of a specific type by  simply checking the class type of the Trackable (as in normal C# programming);

for example:

if (trackable is ImageTarget) ...

 

 

 

How to get current target name in unity

March 5, 2015 - 2:05am #12

Hi,

      I am new to vuforia, I tried this script but I getting below error

Assets/Model1.cs(18,49): error CS0103: The name `TrackableType' does not exist in the current context
Sorry for bad english.
Please Help me AlessandroB
AttachmentSize
Image icon Script.png195.25 KB

How to get current target name in unity

July 16, 2013 - 12:12am #11

 glad to help!

How to get current target name in unity

July 15, 2013 - 11:37pm #10

hi,

 The problem was sovled,thank you for you code.

OMG,I make a silly mistake.It's woking fine now.

 Thank you very much for your answer.

Have a nice day!

How to get current target name in unity

July 15, 2013 - 11:14pm #9

Can you try this script, attaching it to the ARCamera ?


public class TargetLister : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () 
	{
		StateManager sm = TrackerManager.Instance.GetStateManager();
		IEnumerable<TrackableBehaviour> tbs = sm.GetActiveTrackableBehaviours();
		
		foreach(TrackableBehaviour tb in tbs)
		{
			string name = tb.TrackableName;
			if (tb.GetType().Equals(TrackableType.IMAGE_TARGET))
			{
				ImageTarget it = tb.Trackable as ImageTarget;
				Vector2 size = it.GetSize ();
				
				Debug.Log ("Active image target:" + name + "  -size: " + size.x + ", " + size.y);
			}
		}
	}
}

This works for me.

 

How to get current target name in unity

July 15, 2013 - 7:48pm #8

Hi,

 I'm try putting my code in Update() method of  DefaulTrackableEventHandler script.

and I get the same error.

what's wrong?

There is a private member variable named mTrackableBehaviour of DefaultTrackableeventHandler class.

i'm try using string name =  mTrackableBehaviour.Trackable.Name;  get the imagetarget name.

But I always obtain predefined image targte's name ,it's not the result I want.

How to get current target name in unity

July 15, 2013 - 7:49am #7

Can you try putting your code in one of the esisting scripts of our samples, for instance in the DefaulTrackableEventHandler script that is attached to each trackable in the ImageTargets sample ?

just to see if you obtain th same error in that case...

 

How to get current target name in unity

July 15, 2013 - 3:06am #6

and I can not obtain any member of TrackableBehaviour class.

The MonoDevelop show  Trackable is unresolved member "Trackable"

How to get current target name in unity

July 15, 2013 - 2:58am #5

Yes,I'm sure.

How to get current target name in unity

July 15, 2013 - 2:56am #4

Can you add this line at the beginning of your file:

using System.Collections.Generic;

?

 

How to get current target name in unity

July 15, 2013 - 2:53am #3

hi AlessandroB,

 Thanks for your help. but I still can not get the target name.

Follow is my code:

    StateManagerImpl stateManager = (StateManagerImpl) TrackerManager.Instance.GetStateManager();
    
     IEnumerable<TrackableBehaviour> trackableBehaviour =  stateManager.GetActiveTrackableBehaviours();
        
     string name = trackableBehaviour.Trackable.Name();

 

There is an error:

   error CS1061: Type `System.Collections.Generic.IEnumerable<TrackableBehaviour>' does not contain a definition for `Trackable' and no extension method `Trackable' of type `System.Collections.Generic.IEnumerable<TrackableBehaviour>' could be found (are you missing a using directive or an assembly reference?)

I'm a newer.
what maybe the problem?

How to get current target name in unity

July 15, 2013 - 12:48am #2

Hi,

in order to get the currently tracked targets, you can use the GetActiveTrackableBehaviours() method of the StateManager class, see API reference:

https://developer.vuforia.com/resources/api/unity/class_state_manager

Then, for a given trackable you can get the name using the Name() method of the Trackable class, see API reference:

https://developer.vuforia.com/resources/api/unity/interface_trackable

i.e. string name = trackable.Name();

If your trackable is an Image Target, then you can cast your trackable to an instance of ImageTarget and then can obtain its size using the GetSize() method of the ImageTarget class:

https://developer.vuforia.com/resources/api/unity/interface_trackable

 

Topic locked