This website uses cookies to enhance the user experience

Augmented Reality (AR) Development

Share:

Unreal Engine provides robust tools for creating Augmented Reality (AR) experiences within your applications. AR superimposes digital content onto the real world, adding an extra layer of interaction and engagement for your application's users. This tutorial chapter will guide you through the process of developing AR experiences in Unreal Engine, explaining different components and showing you how to work with the ARKit and ARCore plugins.

To incorporate AR experiences within your Unreal Engine project, you need to have the ARKit (for iOS devices) or ARCore (for Android devices) plugins enabled. Navigate to your project's settings in Unreal Editor and select Plugins > Built-in. Search for Apple ARKit or Google ARCore and enable the plugin that corresponds to your target platform.

Now let's get our hands on creating an AR-enabled Unreal project. We will create a project called "ARHogwarts". The AR view will start by loading a Holographic Hogwarts castle which users can interact with.

First, create a new project in Unreal. Name it "ARHogwarts". In the template selection screen, choose Template > Blank. Ensure that the target platform and the type of project are correct (for instance, Mobile/Tablet, With Starter Content). Since we will be working with AR, ensure that the 'AR Support' option is enabled.

On successfully creating the project, Unreal Editor should open up with your ARHogwarts project. The first thing we'll need to work on is creating the AR session configuration. This configuration encapsulates properties like the world alignment, enable plane detection, provide light estimation, etc.

To create the AR session configuration blueprint, navigate to the Content Browser and select Add > Blueprint Class. From the pop-up menu, select ARSessionConfig, and name it "ARHogwartsConfiguration".

// Double click to open the "ARHogwartsConfiguration" blueprint
// Set your configuration options
Set World Alignment to "Gravity"
Set Session Type to "World"
Enable Plane Detection for "Both Horizontal and Vertical"

In the ARHogwarts Configuration, we set World Alignment to 'Gravity' which means the AR objects will align themselves according to the physical world's gravity. Session Type is set to 'World', this implies we are using a world tracking configuration that uses the rear-facing camera to enable AR experiences.

Now let's manage the AR session. You need to create another blueprint for that. Repeat the above process: in Content Browser, Add > Blueprint Class > AActor. Name it "ARHogwartsSession". This blueprint retrieves and maintains the state of our AR session.

// BeginPlay function starts the AR session when you run the ARHogwarts app
Event BeginPlay() {
    // Get ARSession reference from the engine
    AARSessionConfig* HogwartsConfig = GetEngine()->ARSystem->Config;
    // and pass our "ARHogwartsConfiguration" as a parameter
    GetEngine()->ARSystem->Config = HogwartsConfig;

    // Start the AR session
    UARBlueprintLibrary::StartARSession(HogwartsConfig);
}

Now let’s add a simple AR interaction. For this tutorial, we will use an object - a 3D model of the Hogwarts castle. Import a 3D model of Hogwarts (or any other 3D model of your choice). You can utilize Unreal's robust asset import system to bring the models directly into your project.

Next, create a new Blueprint Class: in the content browser, click Add > Blueprint Class > AActor, and name it "HogwartsModelActor". This actor is responsible for spawning the Hogwarts castle model in our AR view.

// When spawned, the actor will instantiate a Hogwarts castle model at a specific location
Event BeginPlay() {
    // Create and position a model at the zero location (0,0,0)
    UStaticMeshComponent* HogwartsModel = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("HogwartsModel"));
    HogwartsModel->SetStaticMesh(LoadObject<UStaticMesh>(NULL, TEXT("StaticMesh'/Game/HogwartsModel.HogwartsModel'")));
    HogwartsModel->SetWorldLocation(FVector(0.0f, 0.0f, 0.0));
}

In the example above, the 3D model of Hogwarts will spawn at location (0,0,0). You can always change these numbers to suit the scene's setup.

Lastly, add this HogwartsModelActor to your main scene via the Unreal Editor's interface. From the 'Place Actors' panel search for "ARHogwartsModelActor", drag and drop it into your scene. Build and launch the application on your AR-enabled device and a holographic Hogwarts castle should appear once the AR session starts!

This chapter covered a fundamental understanding of how Unreal Engine can be used for developing stunning AR experiences. You've learned how to set up and control an AR session, import and use 3D models, and spawn these models within your AR space. In the upcoming chapters, you will learn more complex AR features such as user interactions, animations, complex session controls, and more. Start experimenting with the basic AR features and steadily incorporate more complex ones as you become more comfortable with Unreal Engine's AR functionalities.

0 Comment


Sign up or Log in to leave a comment


Recent job openings