Log in or register to post comments

The model stays on the screen when off the target

July 19, 2011 - 2:50am #24

Hi,

I know I had already read a post about it, but I was unable to find it again...

I have some problems with the target (un)detection. For instance, when I make the target leave the camera too fast, the 3D model still appears on the screen. Or if I put my hand on the device's camera, the screen becomes black, but the 3D model is still there. And to make the model disapear, I have to look at the target again.
I did not encounter this behaviour with QCAR SDK, but only with Unity extension. Did someone fix it?

Re: The model stays on the screen when off the target

July 19, 2011 - 4:25am #23

Have you added a TrackableEventHandler to the target in Unity?

This implements the OnTrackingLost and OnTrackingFound methods that can be used to switch the model rendering on and off in response to tracking events. Check out the TrackableEventHandler script in the ImageTargets sample for an example of how this is done.

Re: The model stays on the screen when off the target

July 20, 2011 - 7:10am #22

Yes, TrackableEventHandler is attached to the target.

I checked, and OnTrackingLost and OnTrackingFound methods are written in it (component.enabled = true when found, and component.enabled = false when lost)

I do not know if it matters, but the result is the same whatever my models are child or not af the target.
And it can't be a problem due to my phone, because I have the same problem on 2 different devices (HTC Desire and Samsung Galaxy tab 7)

I am not sure, but I think that, in my Unity project, if the ARCamera looks at my models, then when the application starts on my phone, I see this ARCamera's point of view, even if the target is not detected yet (hard to explain, I hope you understand... :~ )

Re: The model stays on the screen when off the target

July 20, 2011 - 8:37am #21

Have you checked your debug output using the Eclipse DDMS to confirm whether the trackables are being registered with TrackableBehavior?

I think that the following Log line is in the original code. If not, you can add it to OnTrackingFound and Lost.

e.g.
Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found");

this will show the following in the DDMS 'LogCat' when the target is detected..

INFO/Unity(6229): (Filename: C Line: 0)
INFO/Unity(6229): Trackable chips found
INFO/Unity(6229): UnityEngine.Debug:Internal_Log(Int32, String, Object)

Trackable chips lost is presented when the target is lost by the tracker.
----

What you're describing is similar to the behavior that you'll see when the model is not a child of the target. In this case, the model always renders, but will jump onto the target when it's detected.

Is your model nested in another object? - is it a direct child of the target?

If you can post a screen grab of your Unity screen with the hierarchy and inspector panes open, and a target highlighted, it may help in diagnosing the problem.

Re: The model stays on the screen when off the target

July 20, 2011 - 9:39am #20

Well, it seems that there is no info about Unity in my log... :confused:
Which log do I have to look at?

I tried the application when my model is a child, and when it is not, and it does not change anything. I will try with another project, just to be sure...

I will put a print screen of the unity project tomorrow...

Thanks

Re: The model stays on the screen when off the target

July 20, 2011 - 2:28pm #19

You may need to check 'development build' a/o 'Script Debugging' in Build Settings to enable debug logging.

Re: The model stays on the screen when off the target

July 21, 2011 - 2:31am #18

Hey! I fixed my problem! :D

In fact the TrackableEventHandler script was attached to the target, but the checkButton was not checked, so it acted like there was not any attached script.

That's why I did not see anything linked to this script in the log!

Thanks for your help!

Re: The model stays on the screen when off the target

July 21, 2011 - 7:31am #17

Well... :confused:

On another application, I have the same problem... and the checkButton is checked...

I have 3 different models placed on the same target. When I touch the screen several times, I see first the object1 first, then the object2 etc...
To do that, I wrote one script per object.

Looking in the log, I have this error:
nullreferenceexception object reference not set to an instance of an object
the line with the problem is render.enabled = etc...
It seems that the script doesn't know if it is attached (but it is, and the checkButton is checked, and the object does show or not when it has to be...)

Re: The model stays on the screen when off the target

July 21, 2011 - 3:01pm #16

Hello ACT,

What object is your script attached to? How are you detecting the touch event? Can you post the relevant portion of your script so I can tell what is happening?

The TrackableEventHandler updates both when the status = DETECTEd and TRACKED. You may want to remove the TRACKED check since you want to disable your renderings while the trackable is being tracked.

Thank you,

-Peter

Re: The model stays on the screen when off the target

July 22, 2011 - 3:04am #15

Here is the script for my object (it is the only one). For the second objcet, it is the same thing, except that the model is visible when display == DISPLAY_OBJ2)

using UnityEngine;
using System.Collections;

public class ObjScript : MonoBehaviour {

	public int display = DISPLAY_OBJ1;
	
	public bool touchOnce = false; //The first touch of the screen is not supposed to switch the models, because the user presses the starting button presenting the application.
	public const int DISPLAY_OBJ1 = 1;
	public const int DISPLAY_OBJ2 = 2;
	
	// Use this for initialization
	void Start () {
		Debug.Log(" --------------> Script Obj1 Start() ");
		bool touchOnce = false; 
		display = DISPLAY_OBJ1;//ARCamera.GetComponent<CameraDeviceMenu>().displayMode;
		if(display == DISPLAY_OBJ1){//ARCamera.GetComponent<CameraDeviceMenu>().DISPLAY_OBJ1){
			Debug.Log(" --------------> Script Obj1 Start() gherkin1 displayed");
			renderer.enabled = true;
		}
		else{
			Debug.Log(" --------------> Script Obj1 Start() gherkin1 not displayed");
			renderer.enabled = false;
		}
	
	}	
	
	
	// Update is called once per frame
	void Update () {
		Debug.Log(" --------------> Script Obj1 Update()");
		//SWIPE SCREEN
        // If finger is removed from screen.
		foreach (Touch touch in Input.touches) {
			if (touch.phase == TouchPhase.Ended) {
				if(touchOnce){
					Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=true");
					if(display == DISPLAY_OBJ2){
						display =  DISPLAY_OBJ1;
					}
					else{
						display = DISPLAY_OBJ2;
					}	
				}
				else{
					Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=false");
				}
				touchOnce = true;				
			}
		}
		if(display == DISPLAY_OBJ1){
			renderer.enabled = true;
		}
		else{
			renderer.enabled = false;
		}
	}
}

But I still have the same error with this script.

void Start () {
		renderer.enabled = true;
	}
	
	void Update () {
		renderer.enabled = false;
	}
}

When I look at the target, I briefly see the 2 models, and then I just see the model I am supposed to see (even if I remove TRACKED check in TrackableEventHandler).

If I look at the target and then put my finger in front of the device's camera, the screen becomes black, but the 3D model is still there (and in Log, the lost and found tracker messages are written)

--------------------------------

I started from scratch with your Image target sample. I just attached the first previous script to the teapot, and I have the same problem (the teapot stays on screen when I hide the camera).

Re: The model stays on the screen when off the target

July 22, 2011 - 9:12am #14
Quote:

nullreferenceexception object reference not set to an instance of an object

Where is renderer defined? That may be the culprit.

Re: The model stays on the screen when off the target

July 22, 2011 - 9:36am #13

[QUOTE=Tyro" />Where is [I" />renderer[/I" /> defined? That may be the culprit.[/QUOTE" />

I think that [I" />renderer[/I" /> refers to the GameObject whom the script is attached to.
But I'm not so sure, because the APi is not very clear...

http://unity3d.com/support/documentation/ScriptReference/Renderer.html

Re: The model stays on the screen when off the target

July 22, 2011 - 9:54am #12

You may have to reference the component explicitly using GetComponent();

Here's an example from the samples where all Renderers in child objects are enabled.

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = true;
        }

Re: The model stays on the screen when off the target

July 22, 2011 - 10:03am #11
Tyro wrote:

You may have to reference the component explicitly using GetComponent();

Here's an example from the samples where all Renderers in child objects are enabled.

        Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

        // Enable rendering:
        foreach (Renderer component in rendererComponents) {
            component.enabled = true;
        }

okaaaay... I have this error now :D

Assets/Qualcomm Augmented Reality/Scripts/AR Script/Obj1Script.cs(6,41): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `UnityEngine.Component.GetComponentsInChildren(System.Type)'

Re: The model stays on the screen when off the target

July 25, 2011 - 2:07am #10

I have no errors in my code now, but there is still the problem : The object stays on my screen when I get off the target quickly.

Here is my code now:

using UnityEngine;
using System.Collections;

public class ObjScript : MonoBehaviour {
public Renderer[] rendererComponents;
	public int display = DISPLAY_OBJ1;
	
	public bool touchOnce = false; //The first touch of the screen is not supposed to switch the models, because the user presses the starting button presenting the application.
	public const int DISPLAY_OBJ1 = 1;
	public const int DISPLAY_OBJ2 = 2;
	
	// Use this for initialization
	void Start () {
rendererComponents = GetComponentsInChildren<Renderer>();
		Debug.Log(" --------------> Script Obj1 Start() ");
		bool touchOnce = false; 
		display = DISPLAY_OBJ1;//ARCamera.GetComponent<CameraDeviceMenu>().displayMode;
		if(display == DISPLAY_OBJ1){//ARCamera.GetComponent<CameraDeviceMenu>().DISPLAY_OBJ1){
			Debug.Log(" --------------> Script Obj1 Start() gherkin1 displayed");
			renderer.enabled = true;
		}
		else{
			Debug.Log(" --------------> Script Obj1 Start() gherkin1 not displayed");
			renderer.enabled = false;
		}
	
	}	
	
	
	// Update is called once per frame
	void Update () {
		Debug.Log(" --------------> Script Obj1 Update()");
		//SWIPE SCREEN
        // If finger is removed from screen.
		foreach (Touch touch in Input.touches) {
			if (touch.phase == TouchPhase.Ended) {
				if(touchOnce){
					Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=true");
					if(display == DISPLAY_OBJ2){
						display =  DISPLAY_OBJ1;
					}
					else{
						display = DISPLAY_OBJ2;
					}	
				}
				else{
					Debug.Log(" --------------> Script Obj1 Update() ToucheOnce=false");
				}
				touchOnce = true;				
			}
		}
		if(display == DISPLAY_OBJ1){
			renderer.enabled = true;
		}
		else{
			renderer.enabled = false;
		}
	}
}

Re: The model stays on the screen when off the target

July 26, 2011 - 10:08am #9

Hello ACT,

See the Start() OnTrackableStateChanged() OnTrackingFound() and OnTrackingLost() functions of the TrackableEventHandler.cs that is included with the ImageTargets sample app. In the OnTrackableStageChanged() function you can see how we are checking for the state of the trackable, Detected or Tracked, and then calling OnTrackingLost or OnTrackingFound to enable and disable the rendering of the trackable.

Take a look at the SDK documentation on the SDK tab of our website. Step 3 : Mastering Advanced Topics -> Special Options gives an explanation of responding to tracking events.

Please let me know how implementing these functions in your code goes and if you can get the desired behavior.

Thank you,

-Peter

The model stays on the screen when off the target

November 25, 2015 - 11:41pm #8

what the solution in this problem? i cant make object stay in camera off marker

The model stays on the screen when off the target

May 9, 2016 - 3:53pm #7

Has this problem been solved?

The model stays on the screen when off the target

March 12, 2017 - 8:57am #6

how to do this ?

The model stays on the screen when off the target in run-time

June 10, 2017 - 12:10pm #5

I know this is pretty old a thread. But It seems like most people have this problem. It'd be much better if someone could find a solution to this. I'm facing the same problem now. It works perfectly fine if the 3d model is attached to the target before the run. The problem is when we load the model at run time, it stays in the screen even if the target is lost. I repeat, this happens only when we load the model in run-time. Can someone help?

The model stays on the screen when off the target

August 3, 2017 - 5:08am #4

Hello Everyone, 

I am facing the same issue while loading the 3d model(by using Asset bundle ) at runtime, even the image target is lost then also the model was  appearing in the screen , i tried lot but i can't find the proper solution for this, if anyone find the solution please tell us to solve the issue.

Thanks in advance 

Regards 

Gopi

The model stays on the screen when off the target

August 8, 2017 - 4:46pm #3

At what point is the model loaded? Prior to detecting the image target or when the image target is detected? How is the model attached to the image target object?

Would you be able to provide a small sample project that reproduces this issue?

Thanks,

-Vuforia Support


The model stays on the screen when off the target

January 16, 2018 - 1:49am #2

Hei could u solved the problem?

 

The model stays on the screen when off the target

July 23, 2019 - 7:17am #1

for future questions ... in unity 2019 , I made a slight modification in the code "DefaultModelRecoEventHandler" on the function "OnNewSearchResult"

 

...

if (existingModelTarget)

        {

            modelTargetGameObj = existingModelTarget.gameObject;



            modelTargetGameObj.SetActive(false); // <<<<< add line

        }

...

 

Log in or register to post comments