Unity Integration in React Native

Aug 6, 2024

Unity Integration in React Native

Learn how to integrate Unity games into a React Native app for a seamless, multi-game experience. This guide covers essential steps and tips for creating a unified gaming platform.

Have you ever wished for a single app where you could play multiple games? Imagine the convenience and excitement of switching between your favorite games without needing separate apps. Today, we're diving into how to integrate Unity games into a React Native application, making this dream a reality. With some foundational knowledge of React Native and an understanding of NativeModules, you'll be ready to embark on this exciting journey. Let's get started!

Problem

Integrate unity game in React Native.

Pre-requisite

  • Know the basics of React Native
  • Know about how React Native application interacts using NativeModules

Objectives

  • Users can play multiple games on a single platform
  • To provide a seamless experience while playing the game

Before diving into the topic, let's understand some concepts.


What is Unity?

Unity is a cross-platform game engine developed by Unity Technologies. It can create three-dimensional(3D) and two-dimensional (2D) games, interactive simulations, and other experiences.


What are NativeModules?

The NativeModule system exposes instances of Java/Objective-C/C++ (native) classes to JavaScript (JS) as JS objects, allowing you to execute arbitrary native code from within JS.

Solution

Let's get our hands dirty.

Unity side

Then open the project in Unity and click File โ†’ Build Settings.

Switch to the android platform and check the export project and symlink sources option.

Click on Player settings on the bottom left and make sure that particular checks are checked as per the screenshot below.

Make sure you use IL2CPP in the Scripting Backend and select the target architectures as shown below.

Also, confirm that the strip engine code is checked.

  • Thatโ€™s it. Now go back to build settings and click Export. Select the builds folder inside the project, and you will see that the Android folder will be built.

    Note: Ignore the Adapter performance settings if you get the warning while exporting.

Bonus 

  • If you want to play the game directly in Unity. Itโ€™s easy
    Go to Assets โ†’ Scenes โ†’ Double click on TicTacToe

In unity only, you will below interface. Click on Game, select the aspect ratio and just click the play button โ–ถ๏ธ. Thatโ€™s it.

React Native Side :

First, let's create a new React Native app.

npx react-native init AwesomeTSProject --template react-native-template-typescript

For integrating the unity game, we need to install a package named @azesmway/react-native-unity. Refer to the this link.


Code Explanation :

  • Create a unity folder and also builds a subfolder as seen in the below screenshot. Now copy and paste the android folder generated from the unity.

First, create a reference to the unity view :

const unityRef = useRef<UnityView>();

To display the unity view, we use the UnityView component provided by the package, and We can get a message from unity to RN by callback of the function onUnityMessage(message) :

 <UnityViewref={unityRef}fullScreen={true}onUnityMessage={result => {console.log('onUnityMessage', result.nativeEvent.message)}}/>

Simple, right?!

To send a message to the unity application/game we use postMessage() function.

unityRef.current.postMessage(message.gameObject,message.methodName,message.message);

To send a message from Unity to React Native, we use the AndroidJavaClass object. Please refer to the ButtonPressed() function below. For more details, please refer to the package mentioned above.

COPYCOPYusing System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using UnityEngine.UI;
using UnityEngine;

public class NativeAPI {
#if UNITY_IOS && !UNITY_EDITOR
  [DllImport("__Internal")]
  public static extern void sendMessageToMobileApp(string message);
#endif
}

public class ButtonBehavior : MonoBehaviour
{
  public void ButtonPressed()
  {
    if (Application.platform == RuntimePlatform.Android)
    {
      using (AndroidJavaClass jc = new AndroidJavaClass("com.azesmwayreactnativeunity.ReactNativeUnityViewManager"))
      {
        jc.CallStatic("sendMessageToMobileApp", "The button has been tapped!");
      }
    }
    else if (Application.platform == RuntimePlatform.IPhonePlayer)
    {
#if UNITY_IOS && !UNITY_EDITOR
      NativeAPI.sendMessageToMobileApp("The button has been tapped!");
#endif
    }
  }
}

You can see the demo video: here๏ปฟ


Conclusion

By integrating Unity games into a React Native app, you're not just merging two powerful technologiesโ€”you're enhancing the gaming experience with seamless transitions and unified access. This guide provides the essential steps to achieve this integration, offering a single platform for multiple games. As you explore and implement these techniques, you'll discover new possibilities in game development and user engagement. Dive in and transform your app into a versatile gaming hub!

Subscribe to Our Newsletter

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
Insight
Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages
Sep 11, 2026

Building Local LLMs Using Dart FFI And llama.cpp: Beyond Wrapper Packages

Build local LLMs in Flutter with Dart FFI and llama.cpp, and see how native bridges, GGUF models, memory management, and token streaming enable private, on-device AI.

Insight
My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong
Sep 11, 2026

My Flutter App Froze With Three Photos on Screen. Here's What I Was Doing Wrong

This blog explains how rethinking Flutterโ€™s image-processing architecture fixed severe performance issues and improved rendering efficiency.

Insight
Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15
Sep 10, 2026

Building a Production-Ready Canva-like Editor with Konva.js, React 19 and Next.js 15

This blog explains how to build a production-ready canvas editor with Konva.js, React, and Next.js, covering architecture, performance, and key engineering decisions.

Insight
What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust
Sep 8, 2026

What a PHP-to-NestJS Banking Migration Taught Us About Architecture, Security, and Trust

This blog explores the architecture, security, performance, and documentation lessons from migrating a legacy PHP/Laravel banking platform to NestJS.

Insight
Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs
Sep 7, 2026

Building Production-Grade Video Thumbnail Scrubbing in the Browser: HLS, Frame Extraction, Caching, and Performance Trade-offs

This blog explains how to build responsive video thumbnail scrubbing in the browser for local files and HLS streams, covering frame extraction, caching, and performance trade-offs.

Insight
The Agent Can See Your App. How Often Can It Look?
Sep 4, 2026

The Agent Can See Your App. How Often Can It Look?

AI coding agents can now interact with mobile apps, but their effectiveness depends on iteration speed. This blog explores how React Native architecture influences feedback loops and AI-driven developer productivity.

Insight
Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists
Sep 1, 2026

Building Interactive Cards from Design JSON Without Killing Your Feed: Overlays, Video, Mute/Unmute, and Lag-Free Lists

Learn how to turn design JSON into interactive, video-enabled cards using overlays, smart media controls, caching, and virtualization without slowing down high-cardinality feeds.

The Right Conversation Can

Save You Six Months.

Book a call