This repository provides a custom communication layer for Netcode for GameObjects (NGO) using Bluetooth as its underlying transport mechanism. The package is designed for Android and requires a minimum target API level of 33.
The transport supports a stable two-device connection using predefined roles (Server and Client). If the client crashes and restarts the application, it can seamlessly reconnect to the server without requiring the host to reconfigure its state.
Below are the key folders and files included in this package:
Plugin: Contains the custom Bluetooth Android plugin and configuration templatesBlueT-release.aar: Precompiled Android pluginManifest_and_gradle_configs.txt: Required lines for Android manifest and Gradle templatesSourceCode_plugin.java: Source code for rebuilding the .aar pluginbuild.gradle.kts: Reference Gradle configuration for plugin reconstruction
Scripts: C# scripts for integrating the Bluetooth transport into your Unity project with Netcode integration, including an example of partial implementationBTforNetcodeExample.cs
To correctly integrate the Bluetooth transport plugin into your Unity project, follow the steps below.
In Unity, navigate to:
Project Settings → Player → Publishing Settings
Enable the following options:
- Custom Main Manifest
- Custom Main Gradle Template
- Custom Gradle Properties Template
These will allow modification of Unity's default Android build configuration.
-
Copy the file
BlueT-release.aarinto your Unity project directory:Assets/Plugins/Android -
Select the
.aarfile inside Unity. In the Inspector, enable:- Load on Startup →
true
Then click Apply.
- Load on Startup →
In the folder:
Assets/Plugins/Android
modify the following files:
AndroidManifest.xmlmainTemplate.gradlegradleTemplate.properties
Add all required lines found in:
These entries are required for Bluetooth permissions, features, and Gradle compatibility with the plugin.
In Unity:
Project Settings → Player → Other Settings
Ensure:
- Target API Level: 33 (mandatory, you can try to rebuild the .aar the only constrain was the trivial use of the library: androidx.annotation.RequiresPermission)
- (the original project used a Minimum API Level = 29)
Import all scripts inside:
Place them in any folder inside Assets, except Plugins or Editor.
If you need to modify or extend the Bluetooth Android plugin, follow the official reconstruction procedure below.
- Open Android Studio and create a new project.
- Choose Gradle Kotlin DSL (gradle.kts) as your configuration (recommended).
- Create a new module, then delete all unnecessary files so that the module is recognized as an Android Library.
In settings.gradle, ensure:
include(":<YourModuleName>")
Remove:
include(":app")
-
Rename:
SourceCode_plugin.java→BluetoothPlugin.java -
Place the file inside your module’s Java source path:
<ModuleDirectory>/src/main/java/com/<YourProjectName>
Inside the module directory, locate:
<ModuleDirectory>/build.gradle.kts
Overwrite its contents with the provided reference configuration:
Sync the project to follow the new gradle rules.
Open the Gradle console and run:
./gradlew :<YourModuleName>:assembleRelease
After the build completes, the generated .aar file will be located in:
<ModuleDirectory>/build/outputs/aar
Use this file to replace BlueT-release.aar in your Unity project.