Skip to content

Personalization Integration Template

Matteo Besenzoni edited this page Apr 22, 2026 · 4 revisions

Target Audience: software developers


Overview

The XR2Learn Unity App Personalization Integration Template demonstrates how a Unity-based XR application can communicate with the Personalization Enablers at runtime. It provides a concrete example of integrating Unity applications with the XR2Learn personalization pipeline using real-time message exchange.

This template shows how predicted user states and personalization decisions produced by the Personalization Enablers can be exchanged with a Unity application using a Publisher/Subscriber communication model. It serves as a reference implementation for developers who want to connect XR applications to the XR2Learn personalization ecosystem.

This integration relies on Redis as a message broker to enable asynchronous communication between Unity applications and the Personalization Enablers.

Communication Architecture

Personalization Enablers and the Unity application communicate by exchanging messages using a Pub/Sub protocol implemented with Redis.

This example includes:

  • Code to connect to Redis in Unity
  • Code to create a publisher and a subscriber in Unity
  • Code defining message formats for communication with the Personalization Enablers

The Unity application includes a simple graphical interface to demonstrate this interaction.

Screenshot of the Unity application interface used to test communication with the Personalization Enablers

Figure: Screenshot of the Unity application demonstrating communication with the Personalization Enablers.

Installing Redis Library

Installing NuGet packages in Unity

Documentation for installing NuGet packages in Unity is available here.

Overview of installation steps

In the Unity project:

  1. Go to Window -> Package Manager -> [+] -> Add Package From Git URL
  2. Paste the following URL:
https://github.com/GlitchEnzo/NuGetForUnity.git?path=/src/NuGetForUnity

Installing NRedisStack NuGet packages

  1. Open NuGet For Unity -> Online
  2. Search for NRedisStack
  3. Select the package and click Install All Selected

Redis Connection in Unity

The UIExample.cs script contains a working example showing how to:

  • Connect to Redis as both a publisher and a subscriber
  • Translate Redis messages into Unity internal variables
  • Publish and receive messages exchanged with the Personalization Enablers

Important implementation note

Running complex Unity logic directly inside Redis subscription callbacks can be difficult to debug in Unity. For example, methods such as ProcessMessageNextActivityLevel in UIExample.cs should only update primitive variables.

More complex updates should be handled inside Unity’s standard lifecycle methods (e.g. Update()), using the primitive values populated by the Redis callbacks.


Running the Application

To run the example application:

  • Set the Redis connection string to the ip:port of the Redis instance
  • Click Connect
  • Select User Level and Activity Level
  • Click Start Activity to publish a message that starts an activity
  • Click Stop Activity to publish a message that stops the current activity
  • Observe the suggested next activity level in the dropdown on the right
  • Click Disconnect to close the Redis connection

Available Builds

A compiled build is provided to allow developers to test the example without building the Unity project themselves:


Message Formats

Unity as Publisher

Channel: start_activity

{
  "id": "id_activity",
  "user_level": "user_level",
  "activity_level": "activity_level"
}

Channel: stop_activity

{
  "id": 0,
  "timestamp": "Date.now()"
}

###Unity as Subscriber

Channel: next_activity_level

{
  "id": "id_previous_activity",
  "next_activity_level": "next_activity_level"
}

Where next_activity_level is an integer value (0, 1, or 2).

See also


Relevant GitHub repository

XR2Learn Personalization Enablers - Personalization Integration Template

Back to Personalization Enablers Overview

Clone this wiki locally