How to simply place a scene in AR?

I have a scene that is not AR compatible. I now want to make it AR compatible.

My scene now contains the WebXR component with the relevant AR settings enabled (VR disabled). It also has the WebARSession component attached. Both are on my root object in the scene, in the same way as indicated by any of the example scenes that use iOS AR in the Samples package, yet whenever I launch the scene, it just seems to run as a normal scene, not an AR scene.

I just want to be able to take my existing scene, and place it on the floor / table as an AR scene.

Any help is appreciated, thanks.

Hi nostalgicbear!

To make your existing scene AR-compatible using Needle Engine, you need to ensure a few key components and settings are correctly configured. Since you have already added the WebXR component with AR settings and the WebARSession, let’s verify some common steps to ensure AR functionality works as expected.

Steps to Configure AR in Your Scene:

  1. WebXR Initialization: Ensure you’re initializing the WebXR session properly in your script. You should start the AR session when the application loads or when a button is pressed.

  2. Session Start Method: Use WebARSession.start() to initiate the AR session correctly.

  3. Anchoring: If you want to place your scene in a specific location (like on a floor/table), you should create an anchor using XRAnchorManager (or a similar API if available in Needle Engine) to place your 3D object or scene correctly in AR.

  4. Camera Configuration: Ensure that your scene’s camera is set to follow the WebXR camera view. You may need to adjust the camera settings within your scene.

Example Code Snippet

Here’s a basic example of how to structure the code in your main scene file for initializing an AR session:

import { WebARSession, WebXR } from "@needle-tools/engine";

class YourARScene {
    constructor() {
        this.arSession = new WebARSession();
        this.xr = new WebXR();
    }

    async init() {
        await this.xr.initialize();

        // Optional: Add touch listeners or buttons to activate AR
        document.getElementById("start-ar").addEventListener("click", () => {
            this.startARSession();
        });
    }

    startARSession() {
        this.arSession.start();
        this.arSession.on('sessionStarted', () => {
            console.log("AR Session Started");
            // Here you can set up your anchors or place your objects
            this.placeSceneOnAR();
        });
    }

    placeSceneOnAR() {
        // Logic to place your 3D objects in the AR environment
        // Example: you may want to add your scene root object to the AR session
    }
}

const arScene = new YourARScene();
arScene.init();

Important Considerations

  • Check Permissions: Make sure your browser has the necessary permissions to access AR features.
  • Device Compatibility: Ensure you’re testing on a device that supports AR (like iOS or Android with appropriate WebXR support).
  • Console Logs: Use console logs to debug if the AR session is starting or if there are any errors.

If these steps don’t work, could you provide specific error messages from the console, or any feedback from the AR session? Also, please confirm the versions of Unity and Needle Engine you’re using. This will help in providing more precise assistance.

1 replies left - Get a PRO license for more AI replies.
thread_p2bhav9CGTnH7z7Cr32tzOHd
Reply to this message to continue the conversation

Hello @nostalgicbear

Just to be sure here’s some basic questions:

  • You opened the scene on an AR compatible phone (iOS or Android) ?
  • You see the button “Enter AR” in the menu? If not does your scene contain the “Needle Menu” component with the disabled menu option?
  • Which NE version are you currrently using?

Hey @marcel
Happy New Year!

  • I am opening it on an iOS device (iPhone 12 - using Safari)
  • I have the Needle Menu component added, but I do NOT see the “Enter AR” button.
  • Version 3.47.2-pre (I know this is old but Im not ready to upgrade just yet)


Hey, it looks like “Use QuickLook Export” is turned off in the WebXR component – can you please turn it on?

On 3.47 the button you see at runtime might be called “Open QuickLook”, we later renamed it to “Enter AR” for consistency.

Thanks @hybridherbst , that did it in the end.

A lot of the colour on my materials are not exporting but I will raise that as a separate issue.

Glad to hear!
Please do – depending on which iOS version you’re on there are some things that Apple simply doesn’t support. We’re doing our best on the Needle side to make it work though :slight_smile:

1 Like