beamm_flutter_unity_widget 0.1.6+10

  • Readme
  • Changelog
  • Installing
  • 59

beamm_flutter_unity_widget #

All Contributors

version MIT License PRs Welcome

Watch on GitHub Star on GitHub


Flutter unity 3D widget for embedding unity in flutter. Now you can make awesome gamified features of your app in Unity and get it rendered in a Flutter app both in fullscreen and embeddable mode. Works great on Android and iOS. There are now two unity app examples in the unity folder, one with the default scene and another based on Unity AR foundation samples.

Note: I have updated the example for Unity 2019.3.5 and there are some new changes in the scripts folder. Please replace your already copied files and folders in your unity project

Installation #

First depend on the library by adding this to your packages pubspec.yaml:

  flutter_unity_widget: ^0.1.6+8

Now inside your Dart code you can import it.

import 'package:flutter_unity_widget/flutter_unity_widget.dart';

Preview #

30 fps gifs, showcasing communication between Flutter and Unity:

gif gif

Setup Project #

For this, there is also a video tutorial, which you can find a here.

Add Unity Project #

  1. Create an unity project, Example: 'UnityDemoApp'.
  2. Create a folder named unity in flutter project folder.
  3. Move unity project folder to unity folder.

Now your project files should look like this.

├── android
├── ios
├── lib
├── test
├── unity
│   └── <Your Unity Project>    // Example: UnityDemoApp
├── pubspec.yml

Configure Player Settings #

  1. First Open Unity Project.

  2. Click Menu: File => Build Settings

Be sure you have at least one scene added to your build.

  1. => Player Settings

    Android Platform:

    1. Make sure your Graphics APIs are set to OpenGLES3 with a fallback to OpenGLES2 (no Vulkan)

    2. Change Scripting Backend to IL2CPP.

    3. Mark the following Target Architectures :

      • ARMv7 ✅
      • ARM64 ✅
      • x86 ✅ (In Unity Version 2019.2+, this feature is not avaliable due to the lack of Unity Official Support)

iOS Platform: 1. This only works with Unity version >=2019.3 because uses Unity as a library! 2. Depending on where you want to test or run your app, (simulator or physical device), you should select the appropriate SDK on Target SDK.

Add Unity Build Scripts and Export #

Copy Build.cs and XCodePostBuild.cs to unity/<Your Unity Project>/Assets/Scripts/Editor/

Open your unity project in Unity Editor. Now you can export the Unity project with Flutter/Export Android (for Unity versions up to 2019.2), Flutter/Export Android (Unity 2019.3.*) (for Unity versions 2019.3 and up, which uses the new Unity as a Library export format), or Flutter/Export IOS menu.

Android will export unity project to android/UnityExport.

IOS will export unity project to ios/UnityExport.

Android Platform Only

  1. After exporting the unity game, open Android Studio and and add the Unity Classes Java .jar file as a module to the unity project. You just need to do this once if you are exporting from the same version of Unity everytime. The .jar file is located in the <Your Flutter Project>/android/UnityExport/lib folder
  2. Add the following to your <Your Flutter Project>/android/settings.gradlefile:
include ":UnityExport"
project(":UnityExport").projectDir = file("./UnityExport")
  1. If using Unity 2019.2 or older, open build.gradle of UnityExport module and replace the dependencies with
    dependencies {
        implementation project(':unity-classes') // the unity classes module you added from step 1
  1. To build a release package, you need to add signconfig in UnityExport/build.gradle. The code below use the debug signConfig for all buildTypes, which can be changed as you well if you need specify signConfig.
    buildTypes {
        release {
            signingConfig signingConfigs.debug
        debug {
            signingConfig signingConfigs.debug
            signingConfig signingConfigs.debug
        innerTest {
            matchingFallbacks = ['debug', 'release']
  1. If you found the duplicate app icons on your launcher after installing the app, you can just open UnityExport Manifest file and comment the codes below
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
//      <intent-filter>
//        <action android:name="android.intent.action.MAIN" />
//        <category android:name="android.intent.category.LAUNCHER" />
//        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
//      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />

iOS Platform Only

  1. open your ios/Runner.xcworkspace (workspace!, not the project) in Xcode and add the exported project in the workspace root (with a right click in the Navigator, not on an item -> Add Files to “Runner” -> add the UnityExport/Unity-Iphone.xcodeproj file
  2. Select the Unity-iPhone/Data folder and change the Target Membership for Data folder to UnityFramework
  3. Add this to your Runner/Runner/Runner-Bridging-Header.h
#import "UnityUtils.h"
  1. Add to Runner/Runner/AppDelegate.swift before the GeneratedPluginRegistrant call:
InitArgs(CommandLine.argc, CommandLine.unsafeArgv)

Or when using Objective-C your main.m should look like this:

#import "UnityUtils.h"

int main(int argc, char * argv[]) {
  @autoreleasepool {
    InitArgs(argc, argv);
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  1. Opt-in to the embedded views preview by adding a boolean property to the app's Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

  2. Add UnityFramework.framework as a Library to the Runner project

AR Foundation ( requires Unity 2019.3.*) #


Check out the Unity AR Foundation Samples Demo Repository

The Demo Repository is not guaranteed to be up-to-date with the latest flutter-unity-view-widget master. Make sure to follow the steps listed below for setting up AR Foundation on iOS and Android in your projects.


Go to target info list on Xcode and add this key and value;

key: Privacy - Camera Usage Description value: $(PRODUCT_NAME) uses Cameras


If you want to use Unity for integrating Augmented Reality in your Flutter app, a few more changes are required:

  1. Export the Unity Project as previously stated (using the Editor Build script).
  2. Check if the exported project includes all required Unity libraries (.so) files (lib/\<architecture\>/ and There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk of your AR project, unzip the resulting apk, and copy over the missing .lib files to the UnityExport module.
  3. Similar to how you've created the unity-classes module in Android Studio, create similar modules for all exported .aar and .jar files in the UnityExport/libs folder (arcore_client.aar, unityandroidpermissions.aar, UnityARCore.aar).
  4. Update the build.gradle script of the UnityExport module to depend on the new modules (again, similar to how it depends on unity-classes).
  5. Finally, update your Dart code build method where you include the UnityWidget and add isARScene: true,. Sadly, this does have the side effect of making your Flutter activity act in full screen, as Unity requires control of your Activity for running in AR, and it makes several modifications to your Activity as a result (including setting it to full screen).

Add UnityMessageManager Support #

Copy UnityMessageManager.cs to your unity project.

Copy this folder JsonDotNet to your unity project.

Copy link.xml to your unity project.

(2019.3.5* only) Copy this folder Plugins to your unity project.

Vuforia #


Similar to setting up AR Foundation, but creating a module for the VuforiaWrapper instead.

Thanks to @PiotrxKolasinski for writing down the exact steps:

  1. Change in build.gradle: implementation(name: 'VuforiaWrapper', ext:'aar') to implementation project(':VuforiaWrapper')
  2. In settings.gradle in the first line at the end add: ':VuforiaWrapper'
  3. From menu: File -> New -> New Module choose "import .JAR/.AAR Package" and add lib VuforiaWrapper.arr. Move generated folder to android/
  4. In Widget UnityWidget add field: isARScene: true
  5. Your App need camera permission (you can set in settings on mobile)

Examples #

Simple Example #

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

class UnityDemoScreen extends StatefulWidget {

  UnityDemoScreen({Key key}) : super(key: key);

  _UnityDemoScreenState createState() => _UnityDemoScreenState();

class _UnityDemoScreenState extends State<UnityDemoScreen>{
  static final GlobalKey<ScaffoldState> _scaffoldKey =
  UnityWidgetController _unityWidgetController;

  Widget build(BuildContext context) {

    return Scaffold(
      key: _scaffoldKey,
      body: SafeArea(
        bottom: false,
        child: WillPopScope(
          onWillPop: () {
            // Pop the category page if Android back button is pressed.
          child: Container(
            color: colorYellow,
            child: UnityWidget(
              onUnityViewCreated: onUnityCreated,

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;

Communicating with and from Unity #

import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  _MyAppState createState() => _MyAppState();

class _MyAppState extends State<MyApp> {
  static final GlobalKey<ScaffoldState> _scaffoldKey =
  UnityWidgetController _unityWidgetController;
  double _sliderValue = 0.0;

  void initState() {

  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: const Text('Unity Flutter Demo'),
        body: Card(
          margin: const EdgeInsets.all(8),
          clipBehavior: Clip.antiAlias,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20.0),
          child: Stack(
            children: <Widget>[
                onUnityViewCreated: onUnityCreated,
                isARScene: false,
                onUnityMessage: onUnityMessage,
                bottom: 20,
                left: 20,
                right: 20,
                child: Card(
                  elevation: 10,
                  child: Column(
                    children: <Widget>[
                        padding: const EdgeInsets.only(top: 20),
                        child: Text("Rotation speed:"),
                        onChanged: (value) {
                          setState(() {
                            _sliderValue = value;
                        value: _sliderValue,
                        min: 0,
                        max: 20,

  // Communcation from Flutter to Unity
  void setRotationSpeed(String speed) {

  // Communication from Unity to Flutter
  void onUnityMessage(controller, message) {
    print('Received message from unity: ${message.toString()}');

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;


  • pause() (Use this to pause unity player)
  • resume() (Use this to resume unity player)
  • postMessage(String gameObject, methodName, message) (Allows you invoke commands in Unity from flutter)
  • onUnityMessage(data) (Unity to flutter bindding and listener)

Known issues #

  • Android Export requires several manual changes
  • Using AR will make the activity run in full screen (hiding status and navigation bar).

Contributors ✨ #

Thanks goes to these wonderful people (emoji key):

Rex Raphael
Rex Raphael

💻 📖 💬 🐛 👀
Thomas Stockx
Thomas Stockx

💻 📖 💬
Kris Pypen
Kris Pypen

💻 📖 💬
Lorant Csonka
Lorant Csonka

📖 📹

This project follows the all-contributors specification. Contributions of any kind welcome!

0.1.6+8 #

  • Breaking change for unityframework iOS

0.1.6+7 #

  • Breaking change for unityframework iOS

0.1.6+6 #

  • Breaking change for unityframework iOS

0.1.6+5 #

0.1.6+4 #

  • Improved description

0.1.6+3 #

0.1.6+2 #

0.1.6+1 #

  • Adding Metal renderer support (on iOS) @krispypen

0.1.6 #

  • iOS support for the Unity 2019.3 new export format Unity as a Library @krispypen

0.1.5 #

  • Android support for the Unity 2019.3 new export format Unity as a Library @thomas-stockx

0.1.4 #

0.1.3+4 #

  • Change input source of Flutter touch events so they work in Unity @thomas-stockx
  • Instructions on how to implement Vuforia AR
  • Fix postMessage throwing exceptions on Android @thomas-stockx
  • Add video tutorial, replace unity-player with unity-classes in example @lorant-csonka-planorama
  • Remove java and UnityPlayer changes to the windowmanager @thomas-stockx

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  beamm_flutter_unity_widget: ^0.1.6+10

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:beamm_flutter_unity_widget/flutter_unity_widget.dart';
import 'package:beamm_flutter_unity_widget/generated/i18n.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux


  • package:beamm_flutter_unity_widget/flutter_unity_widget.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web


  • package:beamm_flutter_unity_widget/flutter_unity_widget.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows


  • package:beamm_flutter_unity_widget/flutter_unity_widget.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS


  • package:beamm_flutter_unity_widget/flutter_unity_widget.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart


  • beamm_flutter_unity_widget that is a package requiring null.

Health suggestions

Format lib/flutter_unity_widget.dart.

Run flutter format to format lib/flutter_unity_widget.dart.

Format lib/generated/i18n.dart.

Run flutter format to format lib/generated/i18n.dart.

Maintenance issues and suggestions

Homepage URL doesn't exist. (-20 points)

At the time of the analysis the homepage field was unreachable.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and beamm_flutter_unity_widget.dart. Packages with multiple examples should provide example/

For more information see the pub package layout conventions.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies