- Home /
How can I keep objects invisible when vuforia ImageTarget is lost and found again?
I have several objects inside an ImageTarget. When I click on one of this objects the others dissapear (I disable the mesh renderer component of these objects).
My problem is that if the target is lost and refound, all objects come visible again.
How can I keep these objects invisible even if target is lost?
You could make a boolean that turns true when a target has been picked and have the other objects check when that boolean is false again before they come back on.
Answer by kwalkup · Jun 12, 2019 at 02:18 PM
I believe you can do this by editing the Vuforia script, "DefaultTrackableEventHandler" that is attached to you Image Target. See this method on line 84 (under region "PROTECTED METHODS").
I would add a case for if an object is clicked, like a bool isClicked.
(This code was not tested!) ( Also I apologize for the odd formatting, this is my first time posting an answer.)
// add private bool isClicked;
protected virtual void OnTrackingFound()
{
var rendererComponents = GetComponentsInChildren<Renderer>(true);
var colliderComponents = GetComponentsInChildren<Collider>(true);
var canvasComponents = GetComponentsInChildren<Canvas>(true);
if (isClicked == false)
{
//Vuforia's code:
// Enable rendering:
foreach (var component in rendererComponents)
component.enabled = true;
// Enable colliders:
foreach (var component in colliderComponents)
component.enabled = true;
// Enable canvas':
foreach (var component in canvasComponents)
component.enabled = true;
}
else if(isClicked == true)
{
foreach (var component in rendererComponents)
component.enabled = false;
foreach (var component in colliderComponents)
component.enabled = false;
foreach (var component in canvasComponents)
component.enabled = false;
}
}
I hope this helps, or at least steers you in the right direction! (:
Thank you for your help. $$anonymous$$y problem is I'm so nooby with unity. I don't know how to attach this bool to every object.
I tried to add the variable in a script and then I attached the script to every object but then when I edit de Vuforia Script my script (and variable) are not accesible from here.
Your answer
Follow this Question
Related Questions
Renderer on object disabled after level reload 1 Answer
Heating Issue in AR android app 1 Answer
Cloud recognition in Vuforia 0 Answers
Unity 5.3.4f1 + Vuforia 5.5.9 = error 3 Answers