36

Does anyone have any experience combining React Native and Unity? I'm looking to start a Unity project that's very UI Heavy and I'm thinking about using React Native to take advantage of its UI capabilities on mobile and web.

I'm curious what the workflow for such an approach would be.

user3071284
  • 6,955
  • 6
  • 43
  • 57
Jimmy Xu
  • 689
  • 1
  • 5
  • 14

4 Answers4

18

Finally after a lot of trials managed to do this. These are the steps.

  • 1) Using this link, export android project for Gradle. Select Gradle in the Build Settings window and check the Export Project checkbox. Click Export and select the destination folder.
  • 2) Import the generated folder in Android studio. Select ok whenever prompted. In this process, you will encounter following issues
  • 2a) Gradle Sync Failed due to org.gradle.api.internal.tasks issues. Resolve using this link
  • 3) Create React Native App using this link
  • 4) Start Integrating Android exported folder inside created react native app using this link. Don't upgrade Gradle as Android studio will ask you again and again. You will encounter following issues. Don't go through "Test Integration" until you are finished with #5 here.
  • 4a) While configuring maven, use this url for maven url "$rootDir/../node_modules/react-native/android" .
  • 4b) While configuring maven, if you encounter problem related to javax.inject:javax.inject". Use this link.
  • 4c) You may also encounter this error "Conflict with dependency 'com.google.code.findbugs:jsr305'". You can solve this link.
  • 4d) During Code integration section of this link, focus on the following section: If you are using a starter kit for React Native, replace the "HelloWorld" string with the one in your index.android.js file (it’s the first argument to the AppRegistry.registerComponent() method). Here you have to replace with project name.
  • 5) Before going through "Test your Integration" section, you have to add code to call MyReactActivity from UnityActivity. This link will help.
  • 6) Go through "Test your Integration" section of link provided in #4. You may encounter following problems.
  • 6a) unable to load script from assets index.android.bundle. Use this link.
  • 6b) could not connect to development server on android. Use this link.
Shaunak Das
  • 201
  • 2
  • 4
7

Check my article on Medium

I've shown with an example on How to integrate react native with Unity 3D step by step. My aim was to use the react native within the Unity3D like a module which is quite convenient if you're gonna heavily work on Unity 3D. Hope this helps for someone who comes here later.

Akbarsha
  • 2,422
  • 23
  • 34
  • Do you have any idea that how can we add two or more games in react native app – Anuj Sharma Feb 27 '21 at 12:13
  • Ideally, Unity runs one game in its container. In that case, I'd suggest you try adding Unity games inside an android fragment and use that in react native if it supports rendering fragments. Otherwise rely on Android activity with Unity game fragments @AnujSharma – Akbarsha Mar 30 '21 at 06:51
4

I'm unsure as how a Unity game is built for iOS, if it uses Cocoa Touch for rendering its core classes.

If it does, and you have access or ability to render a UIViewController then you can render your React Native application. The only thing you would have to facilitate is setting up communication between the two applications.

Here is an example of rendering a native UI Component inside a React Native app that may help. http://moduscreate.com/leverage-existing-ios-views-react-native-app/

stan229
  • 2,592
  • 19
  • 23
1

I was curious as well, and created an example project of how to do this for Android: https://github.com/marijnz/unity-react.

If this is a viable option, at least depends on:

  • How long the project will be running, both React and Unity have to be updated and this gets probably tougher over time.
  • The amount of sdk's/dependencies the project has.
  • If you want to do iOS as well.

In general, I'd probably avoid going this way. Even though the example seems pretty simple now, it was a pain to get to that (as Shaunak's answer already hints at ;))