Develop Your Next Mobile Game with Unity and Flutter. Unlock New Possibilities
Your app must always stand out from the competition. Only how can you catch users’ attention? One way is to use advanced animations, but let’s take it further.
I propose gamification. It’s nice to offer a reward for loyal users. In the case of mobile apps, you can entertain them by implementing a small game or making components more interactive and visually appealing.
Learn how to combine Flutter and Unity and what you can include in your games on both platforms, thanks to Flutter.
Ideas for using Unity and Flutter in your projects
If you have ever encountered Unity, it was most likely related to mobile game development. However, this technology offers much more.
Unity in VR/AR projects
For example, if you have an eCommerce app, you may use Unity to display your products in a setting imitating the real world. Augmented Reality technology offers this opportunity but usually at a more significant cost because the team must simultaneously process Unity and Flutter.
3D models
You can expand Flutter’s possibilities by introducing support for 3D models only. Through packages like model_viewer_plus, app developers can embed and interact with 3D models (to an extent) within the Flutter application. As a result, there’s even no need for using Unity.
Chat and forum
Maybe you’d like to enhance social interactions via chat or a forum? Take inspiration from the industry trailblazers like Tencent which ingeniously harnessed the power of this integration in PUBG Mobile. They aimed to enable users to share gameplay clips using a Flutter-made forum integrated within the Unity gaming environment.
Animations
The Unity and Flutter combination is also great for animations. Maybe your company has a mascot, like Duo in Duolingo or Mickey Mouse for Disney? Create a game with these mascots in it. It could be especially helpful when targeting an app for a younger audience.
The key is to allocate your resources wisely. The Unity team should focus on the mobile game, including modeling and polishing the details. Meanwhile, the Flutter team should concentrate on UI-related elements suitable for the target platform. That way, you can reduce the time needed to implement the separate features.
How does Unity work with Flutter?
To seamlessly integrate Unity with Flutter, developers can utilize a package called flutter_unity_widget, created by juicycleff. This package facilitates the embedding of Unity within Flutter applications.
It establishes communication between the Flutter app and the Unity project by leveraging the platform’s channel mechanism. Consequently, developers can directly interact with Unity through Flutter widgets, enabling a cohesive user experience across both platforms.
The behavior of Flutter parts can be easily influenced by the elements in the Unity Scene. For example, you can set up communication to handle the acquisition of new achievements in games via Flutter logic. Just use specific triggers that send data to our Flutter side while maintaining the game loop and removing excess logic.
Use a package written by juicycleff called flutter_unity_widget. It handles embedding Unity in Flutter apps. This package uses the platform’s channel mechanism to communicate with the Unity project. It allows you to communicate directly with the native Android/iOS code to render it in a platform-specific view. As a result, you can interact with Unity using Flutter widgets.
Showcase of communication between Flutter and Unity from the example given in the Flutter Unity widget package.
Implementing games with Flutter and Unity
Most people familiar with mobile game development consider using the Unity game engine. And they can’t be wrong, especially when they care about the players’ 3D experiences. However, if the number of screens running 3D is marginal, consider separating the work for both Flutter and Unity.
How does it work then? Does Flutter allow for both-way communication?
First, you need to set up your Unity editor for the release supported by Flutter_unity_widget. You can download it via Unity Hub. After that, you can use the extensive setup instructions for Flutter and Unity, which are written in the package description.
Once you finish the setup using the interfaces exposed in Unity, you can synchronize 3D elements with the dynamic updates flowing from the Flutter environment. A perfect example of this synergy is the seamless interaction between a slider component in Flutter and its corresponding impact on the rotation speed of a cube rendered in Unity.
The implementation enables two-way communication. Developers can establish functionalities on the Flutter side to respond to user interactions within the Unity-rendered scene.
For instance, tapping on the cube could trigger the invocation of a dialog box within the Flutter interface, improving the user experience.
The platform channel mechanism makes all of this possible. It connects to Unity, which runs on the native platform, making it as efficient as possible.
What can go wrong?
Transforming the mobile game with Unity can be costly if the project has been developed for an extensive period.
You will also need to write communication between Flutter and Unity, which takes some time.
What else should you watch out for? You need to check if all the plugins used in the game work properly, for example, Unity ads or Unity in-app purchases. You may need to move them to Flutter.
It’s best to plan ahead and determine which features can be created with which technology so you can predict whether this will benefit your project.
Implementing Flutter games without Unity
I have a surprise for all mobile game developers out there. Creating games in Flutter is possible!
Google and the Flutter community are heavily involved in delivering tools that developers can use for game development. There’s even a subpage dedicated to games written with Flutter, full of examples, tutorials, and case studies. More helpful products, such as Google Mobile Ads, have become available to developers.
But it doesn’t end here. The Flutter team holds a competition called the Global Gamers Challenge, which shows its dedication to making Dart and Flutter more recognized among game developers.
What do you need to know to start using Flutter for game development?
I wouldn’t recommend using Flutter as a platform to rely on creating a fully 3D experience.
However, with Flutter, you can easily build 2D games with an isometric orientation and a pixel art style. Of course, this is just an example; you can choose whatever style you like.
To help you with this task, a community developed the flame_engine. This modular game engine provides out-of-the-box solutions for game development with Flutter (such as sprite handling, animations, and collision detection).
Flame enables you to use its effective game loop with multiple integrations to different features you might need, such as flame_audio for audio playback or flame_rive for interactive animations made with Rive software.
More tools to come
Rive is a particularly interesting solution for developing Flutter games. The Rive team is now working on Flutter GameKit, an additional engine based on the Rive Renderer. The tool is currently in the technical preview, but it already amazes me how many new possibilities are about to come. For more information about the Flutter GameKit, visit Rive’s official website.
Everything mentioned above will facilitate creating your app. However, you can write your game even without those extra tools. An excellent example of this would be Lost Vault, introduced at the end of 2021. As you can see, years go by and the game still works well and it is quite popular!
A matter of performance
If you wonder how well Unity runs inside your Flutter app, prepare for a smooth performance. How is this possible? There are many optimizations available. Unity can be loaded on startup and stored in the memory. Then, the scenes meant to be loaded change. Alternatively, some resources are released when users close the game tab.
Using the flame engine will significantly improve performance, but it’s limited to games and animations in the 2D setting.
In this article, I explained how game developers can use Flutter to experiment with current or future projects. I also wanted to shed some light on the possibilities built into the Flame engine and what’s coming to us in the future, thanks to Rive. If you have any questions, feel free to contact us.
FAQ
What are the benefits of Unity and Flutter integration for mobile games?
The most important benefit is that Unity’s robust 3D rendering capabilities for mobile game development and Flutter’s smooth UI render allow us to create visually stunning mobile games. What’s more, flexible development can be streamlined in two different areas at once by leveraging the strengths and roles of both frameworks in the project.
What app development skills do you need to work with Unity and Flutter?
The Unity team must be proficient in the C# programming language. It must also be familiar with the interface, game mechanics, and communication scripting with Flutter. Unity developers also need to acquire some knowledge about 3D models.
The Flutter team must be proficient in the Dart programming language. Additionally, they have to understand the composition of widgets required to work smoothly with Unity. Knowledge of platform-specific APIs is also handy due to the nature of platform channel mechanism usage. A mobile game development background will also improve the team’s understanding of how things work on the other side.