Multiple placement webAR Not working

Continuing the discussion from Multiple objects placements in AR Scene:

not working.
and also, i have a small circle gizmo from needle when it tracks a plane.
so when i add the first object it works, its added then the gizmo isnt there anymore.
and i can zoom in out to scale the object i placed in the webAR scene.
and i can move it where i want
but i cant add another
i have an XR object that has the webXrplanetracking on it
i have a spawner object that has the spawning script
and the prefab to render and raycaster with object raycast

Hi Astuce, it sounds like your session is ā€œlocking inā€ the initial scene placement—once the first object is spawned, the AR session (or its plane-tracking component) marks the scene as placed and hides the plane-tracking gizmo, which in turn prevents additional objects from being added.

In Needle Engine the default behavior (for example, via WebARSessionRoot or similar components) is to finalize placement on the first hit. To allow multiple placements you can try the following:

• Ensure your WebXRPlaneTracking (or similar) component isn’t automatically disabling itself or its gizmo after the first placement. In many cases the AR system hides the reticle once a placement is confirmed.

• Separate your AR scene placement logic from your spawner logic. For example, perform an initial scene placement (using autoPlace or manual placement) and then use a dedicated spawner—driven by its own raycaster for hit-testing—to let you add objects.

• Make sure that your spawned objects are not blocking pointer events. You may need to assign them to a layer or disable their own pointer interactions so that the AR plane remains ā€œclickable.ā€

Below is an example of a simplified spawner component that listens for pointer clicks and spawns a clone of a prefab at the clicked position. (You may need to adjust the code to use the hit-test results from your AR session rather than simply using a pointer position.)

import { Behaviour, serializable, IPointerClickHandler, PointerEventData } from "@needle-tools/engine";
import { Object3D } from "three";

export class MultiplePlacementSpawner extends Behaviour implements IPointerClickHandler {
    // A reference to the prefab to spawn
    @serializable(Object3D)
    prefab: Object3D | null = null;

    // This method is triggered on pointer (or AR hit) events
    onPointerClick(event: PointerEventData) {
        if (!this.prefab) return;
        
        // Clone the prefab
        const clone = this.prefab.clone();
        
        // Here, use the AR hit test result to set the position.
        // For demonstration, we copy the pointer hit's world position.
        // You may need to use event.ray or your AR hit-test result instead.
        clone.position.copy(event.ray.origin);

        // Add the spawned object to the scene
        this.gameObject.scene.add(clone);
        console.log("Spawned an object at", clone.position);
    }
}

Make sure that your spawner script isn’t triggering any ā€œplacement lockedā€ flag. Also, review your XR object’s WebXRPlaneTracking for any logic that disables the gizmo after the first placement. By keeping the plane-tracking active (or by re-enabling it after each spawn) and ensuring that the spawned objects don’t block raycaster events, you should be able to perform multiple placements.

If you continue to have trouble, could you please share your spawner script and any custom configurations on your XR object? That way we can dig deeper into what might be causing the gizmo to disappear after the first placement.

Happy coding!

0 replies left - Become PRO for more replies.
thread_XC8mbN94SirOqpnenpzlizXx
Reply to this post directly if you need further help (bottom right button)

Please dont open multiple posts for the same topic