Search Unity

[XR Interaction Toolkit][AR] Limit placable objects to 1

Discussion in 'AR/VR (XR) Discussion' started by d4n3x, Feb 13, 2020.

  1. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    19
    Dear Community,

    does anybody know if there is any way to limit the AR Objects to 1 with the interaction toolkit? Would be very important to me to know that.

    Thanks in advance
    Danex
     
  2. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    19
    I actually found a (very cruel) way to do it with the toolkit.
    Just add the following script to the PlacementInteractableObject and after placing the first time, you will not be able to place one again till u set the prefab new.


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.XR.Interaction.Toolkit.AR;
    5.  
    6. public class LimitPlaceableObjectsToOne : MonoBehaviour
    7. {
    8.     private ARPlacementInteractable placementInteractable;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         placementInteractable = this.GetComponent<ARPlacementInteractable>();
    13.         ARObjectPlacedEvent aRObjectPlacedEvent = placementInteractable.onObjectPlaced;
    14.         aRObjectPlacedEvent.AddListener(ObjectPlaced);
    15.     }
    16.  
    17.  
    18.     private void ObjectPlaced(ARPlacementInteractable p, GameObject q)
    19.     {
    20.         placementInteractable.placementPrefab = null;
    21.     }
    22. }
    23.  
    Greets Danex

    Update:
    To Fix the Bug below you ned to add the following line to the PlacementInteractable code of the toolkit simply after the raycast:

    Code (CSharp):
    1.  
    2. if(placementPrefab == null)
    3.                     return;
    4.  
     
    Last edited: Feb 13, 2020
  3. d4n3x

    d4n3x

    Joined:
    Jan 23, 2019
    Posts:
    19
    Actually if you want to place a prefab and the placement prefab is set to null - the toolkit breaks. I hope somebody has an solution for this....^^
     
  4. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    113
    we have a bug for this :) will be in the next version!
     
unityunity