Ever wondered how top-tier applications deliver data in the blink of an eye? From the fast-paced world of financial trading to the competitive arena of online gaming, every millisecond counts. This is where Lightstreamer, the high-performance real-time messaging server, shines. Its uniquely optimized algorithms are engineered to push data to mobile, web, and desktop clients with extreme speed and low-latency.

In the world of interactive development, Unity stands as a titan. It’s the cross-platform game engine that powers millions of stunning 2D and 3D games, simulations, and digital experiences. Its rich visual editor, advanced physics engine, and flexible scripting are the trusted tools of developers worldwide.
When these two industry leaders join forces, the result is transformative. Through a seamless Lightstreamer Unity integration, you can supercharge your projects with live, real-time data streams. This isn’t just an upgrade; it’s the key to unlocking a new level of immersion and engagement.
Why Combine Lightstreamer and Unity?
- Instant Synchronization: Instantly update player movements, live scores, and critical game-state changes in perfect unison across all clients.
- Dynamic Visualizations: Create dashboards and data visualization tools that update in real time.
- E-commerce and Trading: Power live online auctions and trading platforms that demand immediate price updates.
Beyond these use cases, countless other applications can benefit wherever real-time data makes the difference.
In this post, we’ll walk you through a practical demo on how to integrate Lightstreamer into a Unity project. Discover how to build an application that consumes real-time data to create a unique and reactive experience.
If you’re ready to see how Lightstreamer can elevate your next Unity project, keep reading.
The Demo: Real-Time Data in Unity
To demonstrate how Lightstreamer can power real-time interactivity inside Unity, we created a simple yet effective demo. At its core, the demo shows how game objects in a Unity 3D scene can react instantly to live data streams coming from the Lightstreamer Server.
The scene features three cubes that continuously change size and color based on updates delivered by the StockList Data Adapter, the same one used in our classic StockList demo. As market data fluctuates, the cubes respond in real time: growing or shrinking along the y-axis and shifting between green and red to reflect changes. Alongside them, several TextMeshPro labels update with live values, while an additional data stream from the Round-Trip demo highlights instant messaging capabilities.

The architecture is simple and flexible. All objects that need to receive updates are grouped under a parent object called World. This object manages the connection to the Lightstreamer Server and distributes updates to its children, each of which can subscribe to specific items or data fields. Once connected, the system takes care of the rest—ensuring that every object in the scene stays perfectly in sync with the incoming real-time data.
The result is a compact but powerful example of how Lightstreamer can bring live, low-latency updates into Unity. From this foundation, developers can imagine extending the same approach to more complex scenarios: multiplayer game states, collaborative 3D environments, or any application where data must flow instantly to every client.
Under the Hood: Lightstreamer Assets in Unity
Behind the scenes, the demo relies on a set of custom Unity Assets—found in the Assets/LS
folder of the GitHub project—that act as the bridge between Unity and the Lightstreamer Server. These components, written in C#, use the Lightstreamer .NET Client Library to establish a session with the server, subscribe to a defined set of items, and handle the incoming stream of updates.
Once updates are received, the Assets take care of redistributing them to the relevant game objects in the scene. This design keeps the connection logic centralized while allowing each object—whether a cube, a label, or a message field—to focus only on reacting to the real-time data it cares about.
LightstreamerClientAsset: Managing the Connection
At the heart of the demo is the LightstreamerClientAsset
class, a Unity MonoBehaviour
that acts as the main gateway between the Unity scene and the Lightstreamer Server.
This component is responsible for:
- Opening a session with the server using the Lightstreamer .NET Client library.
- Scanning the scene for child objects tagged with
lightstreamer
and collecting their subscription parameters (ItemName, Schema, DataAdapter). - Creating and managing subscriptions for those items through the Lightstreamer Client API.
- Redistributing updates received from the server to child objects via Unity’s
BroadcastMessage
, using two message types:RTStatus
for connection status updates.RTUpdates
for real-time data updates.
Internally, the class keeps track of subscriptions and updates through synchronized queues, while a simple state machine in the Update()
method drives the connection and event dispatch flow.
In short, LightstreamerClientAsset
centralizes all the networking logic so that the rest of the scene objects can remain lightweight, focusing only on how to react to incoming data.
In the Unity Editor, the World object hosts the LightstreamerClientAsset
component. Here you can configure the connection parameters:
- Push URL – the endpoint of the Lightstreamer Server (in this demo,
https://push.lightstreamer.com/
). - Adapters Set – the name of the Adapter Set exposed by the server (in this case,
DEMO
).

Once set, these parameters are used by the component to establish the session and manage subscriptions for all child objects tagged with lightstreamer
.
// Initialize the Lightstreamer client and connect
client = new LightstreamerClient(pushUrl, adaptersSet);
client.addListener(new StocklistConnectionListener(this));
client.connect();
// Create and register a subscription for child LightstreamerAssets
Component i = GetComponent<Component>();
Component[] Children = i.GetComponentsInChildren(typeof(Renderer));
foreach (Component child in Children)
{
//child is your child transform
Debug.Log("My child: " + child.tag);
if (child.tag.StartsWith("lightstreamer"))
{
LightstreamerAsset ls = child.GetComponent(typeof(LightstreamerAsset)) as LightstreamerAsset;
if (ls != null)
{
Debug.Log("My child: " + ls.ItemName.Split(',')[0]);
// Add info for a subscription
Subscription sub = new Subscription("MERGE", ls.ItemName.Split(','), ls.Schema.Split(','))
{
DataAdapter = ls.DataAdapter,
RequestedSnapshot = "yes"
};
sub.addListener(new RTQuoteListener(this));
subscriptionsLS.Enqueue(sub);
ls.addSender(this);
}
}
}
👉 The two snippet above show how LightstreamerClientAsset
initializes the connection to the Lightstreamer Server and dynamically subscribes to items defined by its child objects.
// Forward updates from Lightstreamer to Unity objects
BroadcastMessage("RTUpdates", (ItemUpdate)this.nextUpdate.Dequeue());
👉 The snippet above shows how updates received from the server are broadcast to all subscribed child objects, triggering their own RTUpdates()
methods to react to the incoming data.
LightstreamerAsset: the Base Component
Each scene object that needs to react to real-time data is built upon the LightstreamerAsset
class.
This base component defines the contract between Unity objects and the LightstreamerClientAsset
described earlier.
The class exposes a few key properties that describe how the object should subscribe to the data stream:
- ItemName – the name of the item to be subscribed (e.g., a stock symbol).
- Schema – the list of fields to be received from the server.
- DataAdapter – the adapter from which the data should be fetched.
If you want to expose additional configuration options available in the Lightstreamer Client API — for example, changing the subscription mode (which in this demo is fixed to MERGE
), or setting a custom frequency limit for updates from the server — this is the right place to add those parameters. Extending LightstreamerAsset
lets you easily pass them to the Subscription
object when it’s created by the LightstreamerClientAsset
.
Through the addSender()
method, each asset registers its parent LightstreamerClientAsset
, which will take care of wiring up the subscription. Once data flows in, the component provides two hooks:
RTUpdates(ItemUpdate update)
– invoked whenever an update for the subscribed item is received.RTStatus(string status)
– invoked on connection status changes.
By default, the base class just logs the events, but it is designed to be extended so that specialized assets (e.g. cubes, texts, UI panels) can implement custom behavior when real-time updates arrive.
LightstreamerCubeAsset: bringing data to life
LightstreamerCubeAsset
is a specialization of LightstreamerAsset
that turns incoming data updates into visual changes within the Unity scene. Each cube becomes a dynamic indicator reflecting the live performance of a stock item.
Key responsibilities of the class:
- Height adjustment – Through the
SetHeight()
method, the cube resizes along the Y-axis according to the percentage change (pct_change
). Positive changes make it grow upwards, while negative ones make it sink below the baseline (baselineY
). - Color updates – Thanks to the
StockColorUtils
utility, the cube smoothly transitions between shades of green and red depending on the sign and intensity of the change. This provides an immediate and intuitive visual cue. - Connection status feedback – With
RTStatus()
, the cube’s material color reflects the state of the connection with Lightstreamer (e.g., gray when closed, cyan when polling, dark green when streaming). - User interaction – With
OnMouseOver
andOnMouseExit
, the cube highlights itself in yellow when hovered, offering quick visual feedback to the user.
This way, a simple Unity cube becomes a reactive 3D widget, instantly driven by live data and ready to enhance any real-time visualization scenario. In the code snippet below, you can see how easy is to react to a change in the connection state with the Lightstreamer server by changing the color of the object.
new public void RTStatus(String status)
{
if (status.Contains("CLOSE"))
{
myObj.material.color = Color.gray;
}
else if (status.Contains("POLLING"))
{
myObj.material.color = Color.cyan;
}
else if (status.Contains("STREAMING"))
{
myObj.material.color = new Color(70, 90, 70);
}
}
}
Unity Inspector: configuring a cube connected to Lightstreamer

The screenshot shows how a cube looks in Unity when configured with the LightstreamerCubeAsset
component:
- Item Name: the item to subscribe to (in this case,
item2
). - Schema: the fields retrieved from the server (
pct_change,last_price
). - Data Adapter: the adapter providing the data (here
QUOTE_ADAPTER
). - Stock Cube: the
Transform
of the cube itself, which will be scaled and repositioned. - Refscale: a scaling factor controlling how much the percentage change affects the cube’s height.
- Baseline Y: the vertical reference line used to anchor the cube’s base.
With just this configuration, the cube becomes a fully data-driven object, expanding, shrinking, and shifting color in real time as updates flow in from the Lightstreamer server.
Real-Time Labels with LightstreamerLabelAsset
While the cubes provide a vivid, dynamic visualization of stock changes, sometimes raw numbers tell the story best. The LightstreamerLabelAsset
does exactly that: it connects a TextMeshPro
object to a live data field and updates its content in real time.
In this demo, each cube is paired with a label showing the percentage change (pct_change
) received from the Lightstreamer Server. As soon as new values arrive, the label text refreshes instantly, ensuring that the visual growth or shrinkage of the cube is always complemented by precise numerical feedback.
The implementation is intentionally minimal: when the subscribed item receives an update for pct_change
, the label text is updated with the new value plus a %
sign. This simplicity makes the component highly reusable—you can attach it to any TextMeshPro
object in your scene to reflect real-time data alongside the visuals.
new public void RTUpdates(ItemUpdate update)
{
if (!update.ItemName.Equals(this.ItemName)) return;
if (update.ItemName.StartsWith("item"))
{
if (update.isValueChanged("pct_change"))
{
label.text = update.getValue("pct_change") + "%";
}
}
}
👉 The snippet above illustrates how a label seamlessly updates its text in real time whenever the percentage change of its associated stock item changes.
LightstreamerMsgAsset: instant messaging in Unity
After exploring how Lightstreamer updates can directly influence 3D objects and labels in Unity, let’s move into another essential aspect of interactivity: real-time communication between users. This is where the LightstreamerMsgAsset
comes in.
Instead of animating cubes or updating numeric values, this component turns a simple TextMeshPro
object into a live chat window. Every keystroke typed by a user is captured, bundled into a message, and instantly sent upstream to the Lightstreamer Server. On the flip side, whenever the server broadcasts a new message, the label is updated in real time, ensuring that all clients stay perfectly synchronized.
With just a handful of lines, Unity objects can not only reflect market data or status changes but also become conduits for instant messaging. Combined with the other Lightstreamer assets, this creates the foundation for multiplayer chat, collaborative virtual spaces, or any interactive scenario where live user input is just as important as live data feeds.
LightstreamerMsgAsset
focuses on bi-directional communication. It extends LightstreamerAsset
to enable simple instant messaging features inside Unity.
Key aspects of the class:
- User input capture – The
Update()
method listens to keystrokes viaInput.inputString
. Characters are accumulated into a buffer (msgForTheServer
), which is then sent to the Lightstreamer server as a real-time message with the formatRT|0|<message>
. - Message display – The class retrieves a
TextMeshPro
component (TMP_Text
) attached to the same object. When an update for the subscribed item is received, the label is updated in real time with the latest message (update.getValue("message")
). - Message constraints – To keep things manageable, a
MAX_LENGTH
is enforced. If the buffer grows too large, it resets with the newest input.
In practice, this turns any TextMeshPro
label in Unity into a live chat widget, capable of both sending and receiving messages through Lightstreamer. It’s a lightweight yet powerful demonstration of how real-time communication can be seamlessly integrated into a Unity project.
// Capture user input and send to Lightstreamer
string msgFromTheUser = Input.inputString;
if (msgFromTheUser.Length > 0) {
msgForTheServer += msgFromTheUser;
this.sender.SndLsMsg("RT|0|" + msgForTheServer);
}
// Receive and display updates from the server
public override void RTUpdates(ItemUpdate update) {
if (update.ItemName.Equals(this.ItemName) && update.isValueChanged("message")) {
label.text = update.getValue("message");
}
}
👉 The snippet above shows the essence:
- Every keystroke is captured and sent upstream to the Lightstreamer Server.
- When a new message is published back from the server, the on-screen
TextMeshPro
label updates instantly.
A Quick Note on the Data Adapters
Just a quick heads-up: the focus of this demo is purely on the client-side integration with Unity. To keep things simple and get you straight to the action, we’re leveraging existing Lightstreamer Data Adapters that power our public demos (like the popular StockList). These adapters are already running on our server, pushing real-time data for you to consume. If you’re planning to kick off a new project from scratch, remember that you’ll also need to develop your own server-side Data Adapters. This is the essential step where you code the logic for connecting to your specific data source and feeding it into the Lightstreamer Server!
Wrapping Up
From live stock-driven cubes to dynamic labels and instant messaging, this demo shows how Lightstreamer and Unity can work hand in hand to create highly interactive, data-driven experiences.
At the core of the design lies a simple yet powerful idea: let Lightstreamer handle the real-time data delivery, and let Unity bring that data to life in 3D worlds, immersive UIs, or collaborative spaces. Whether you’re building trading dashboards, multiplayer games, or innovative simulation tools, the same building blocks can be reused and extended to fit your vision.
This demo is just a starting point. With a few scripts and some Unity magic, we’ve seen how cubes can grow and change color with market updates, how labels can display precise live values, and how user input can be transformed into real-time conversations.
The possibilities are wide open — any scenario where data must flow instantly between server and client can benefit from this integration.
👉 So, what will you build next?
Useful Links
- The GitHub project of the demo: https://github.com/Lightstreamer/Lightstreamer-example-basic2-client-unity
- The demo leverages the Lightstreamer .NET Standard Client version 6: https://www.nuget.org/packages/Lightstreamer.DotNetStandard.Client/#versions-body-tab
- Unity 6 Development platform: https://unity.com/