c# - Create objects with ground plane detection only once with Vuforia & Unity


Keywords:c# 


Question: 

I am trying to create an AR app using Unity & Vuforia. I have a 3D model that needs to be spawned when ground plane is detected.But this needs to happen only once. The way Vuforia work is, it keeps on spawning objects when new plane is detected. So what i need to do is either detect plane only once or spawn the object only once. As i am new to Unity, i need help doing this. Great if someone could tell me what i need to do to achieve this.


4 Answers: 

In your app you should have a Plane Finder object somewhere with the following properties set by default
enter image description here

The Plane Finder object has a Behaviour component attached that calls a Position Content method if a plane was found. That method belongs to the Content Positioning Behaviour and it makes an instance (Clone) of your Ground Plane Stage. In order to avoid more than one instance you should import the vuforia Deploy Stage Once script located here: and you should change the Plane Finder Behaviour as the following:enter image description here

 

Vuforia has updated.Now There is no DeploymentStageOnce script.Inorder to stop duplicating while we touch, we have to turn off Duplicate Stage in Content Positioning Behaviour (Script)Check the Inspector when we click Plane Finder. enter image description here

 

For Updated Versions:

enter image description here

go to "Advanced" setting and "On Interactive Hit Test" script -> Select "Off" option for the script.

 

I strugled a long with it, in short we must disabled AnchorInputListenerBehaviour after hit. 1.- I attached a new script on PlaneFinder with this code below:

<!-- language-all: c# -->
public void OnInteractiveHitTest(HitTestResult result)
{
    var listenerBehaviour = GetComponent<AnchorInputListenerBehaviour>();
    if (listenerBehaviour != null)
    {
        listenerBehaviour.enabled = false;
    }
}

2.- I added event on Plane Finder Behaviour

enter image description here

That's all, i hope it will be usefull