Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question ARPlacementInteractable places same prefab despite being switched to a new one

Discussion in 'AR' started by UNITY-DEV01-f3p, Jan 5, 2023.

  1. UNITY-DEV01-f3p

    UNITY-DEV01-f3p

    Joined:
    Jul 8, 2019
    Posts:
    2
    (hope i'm doing this right, it's my first forum post)

    Hello everyone, before I break my head over this by myself, I'd rather seek help from you guys.
    We're using ARFoundation (4.1.12) and the XR Interaction toolkit, the latter with quite an outdated version (0.9.4 preview) but with minor customizations.
    It worked before with standard asset bundles, now we updated it to work with addressables (1.21.2). It was "just" a few changes here and there and it works perfectly... At least on Android.
    I don't know what's happening on iOS though... When you choose one prefab to place, it places it just fine. When you choose another object, it places the previously chosen prefab instead of the new one.
    I've already tried updating the tool kit but still same problem

    Here's a snippet of the code
    Code (CSharp):
    1.     private async Task ActivateInternal(ContentPersistent currentEntry) {
    2.         await Addressables.InitializeAsync();
    3.  
    4.         //.......
    5.         //some UI configs happening here
    6.         //.......
    7.  
    8.         var asyncOp = Addressables.LoadAssetAsync<GameObject>(currentEntry.AddressableKey);
    9.         await asyncOp;
    10.         AddressablesManager.Instance.currentLoadedAddressable = asyncOp.Result;
    11.         var go = asyncOp.Result;
    12.  
    13.         Debug.Assert(go != null, $"Could not load GameObject. Key was {currentEntry.AddressableKey}.");
    14.  
    15.         ARPlacementInteractableSingleton.Instance.ARPlacementInteractable.placementPrefab = go;
    16.         var arObjectPlacedEvent = ARPlacementInteractableSingleton.Instance.ARPlacementInteractable.onObjectPlaced;
    17.         arObjectPlacedEvent.RemoveListener(DeactivatePlacement);
    18.         arObjectPlacedEvent.AddListener(DeactivatePlacement);
    19.  
    20.         var removedAllObjectsEvent = ARPlacementInteractableSingleton.Instance.OnRemovedAllObjects;
    21.         removedAllObjectsEvent.RemoveListener(OnRemovedAllObjects);
    22.         removedAllObjectsEvent.AddListener(OnRemovedAllObjects);
    23.  
    24.         //.......
    25.         //some more UI configs happening after
    26.         //.......
    27.     }
    I might rewrite the whole placement code before I waste any more time on my previous coworker's code but I would at least like to know why it's happening :/
    In the editor I can clearly see the "Placement Prefab" of ARPlacementInteractable.cs being changed correctly. Does addressables work differently on iOS then? Is it not being loaded correctly?? But then I should see the debug log in xcode...
     
  2. VRDave_Unity

    VRDave_Unity

    Unity Technologies

    Joined:
    Nov 19, 2021
    Posts:
    260
    Hi @UNITY-DEV01-f3p,

    Please file a bug (
    Help > Report a bug...
    ) with the project attached (or a simplified version of it) so that someone on the XR team can take a look and hopefully help you get to the bottom of this. I will mention that XRI 0.9.4-preview is no longer officially supported and you should probably look into migrating to the 2.x versions of the package as that will be where any fix to the XRI package itself would land.