Version: 2021.2
Using Unity as a Library in other applications
Xcode frame debugger Unity integration

Deep linking

Deep links are URL links outside of your application that direct users to a location in your application. When the user clicks a deep link for an application, the operating system opens the Unity application at a specified place (for example, a specific scene). Unity uses the Application.absoluteURL property and Application.deepLinkActivated event to support deep links on the following platforms:

  • iOS
  • Android
  • Universal Windows PlatformAn IAP feature that supports Microsoft’s In App Purchase simulator, which allows you to test IAP purchase flows on devices before publishing your application. More info
    See in Glossary
    (UWP)
  • macOS

Enabling deep linking

Before you can process deep links, you need to configure your application to react to them. The process to configure an application to react to specific URLs is platform-specific. Unity supports deep links for the following platforms:

Using deep links

To process deep links, you can either:

The following code sample shows you how to process a deep URL and load a sceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
depending on the URL.

using UnityEngine;
using UnityEngine.SceneManagement;

public class ProcessDeepLinkMngr : MonoBehaviour
{
    public static ProcessDeepLinkMngr Instance { get; private set; }
    public string deeplinkURL;
    private void Awake()
    {
        if (Instance == null)
        {
            Instance = this;                
            Application.deepLinkActivated += onDeepLinkActivated;
            if (!string.IsNullOrEmpty(Application.absoluteURL))
            {
                // Cold start and Application.absoluteURL not null so process Deep Link.
                onDeepLinkActivated(Application.absoluteURL);
            }
            // Initialize DeepLink Manager global variable.
            else deeplinkURL = "[none]";
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }
 
    private void onDeepLinkActivated(string url)
    {
        // Update DeepLink Manager global variable, so URL can be accessed from anywhere.
        deeplinkURL = url;
        
// Decode the URL to determine action. 
// In this example, the app expects a link formatted like this:
// unitydl://mylink?scene1
        string sceneName = url.Split("?"[0])[1];
        bool validScene;
        switch (sceneName)
        {
            case "scene1":
                validScene = true;
                break;
            case "scene2":
                validScene = true;
                break;
            default:
                validScene = false;
                break;
        }
        if (validScene) SceneManager.LoadScene(sceneName);
    }
}

Testing deep links

To test a deep link:

  1. Create an HTML file that includes the deep link to test.
  2. Host it on a local web server.
  3. Access it from a web browser on your device and click the link.

Example HTML file

This is an example HTML file that you can use to test deep links. To redirect the link, change the href attribute in one of the <a> elements.

<html>
    <head>
       <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    </head>
    <body >
       <h1>My Deep Link Test page</h1>
       <p><a href="unitydl://mylink">Launch</a></p>
       <p><a href="unitydl://mylink?parameter">Launch with Parameter</a></p>
    </body>
</html>
Using Unity as a Library in other applications
Xcode frame debugger Unity integration