Guide for Unity
Using our Unity SDK Plugin, you can implement the haptic into your content made with Unity.
- Import SDK Plugin
- Link the Haptic App
- Add Prefab for Initialization
Requirements
- Development Environment
- OS: Windows 10/11 (x64), macOS (Apple Silicon) (currently on Beta)
- Unity 2019.4.0+
- bHaptics Player installed
- Deployed haptic application corresponding to your game
- App ID and API Key of the haptic app
- Runtime Environment
- OS: Windows 10/11 (x64), Meta Horizon OS, PS5
About haptic application
You can create and manage haptic apps in Developer Portal, a web-based tool.
If you're unfamiliar with haptic apps or haven't created one yet, please follow the Portal guide before proceeding.
Before linking a haptic app to your game project, make sure the haptic app meets the following requirements:
- At least one haptic event must be created.
- API Key must be generated.
- There is no API Key by default. To generate one, go to the "API Key" tab and click "New" button.
- Haptic app must be deployed
- If you see "Deploy Now" button in the upper right corner, click it to deploy your haptic app. Otherwise, if you can see "Up to date", it means that the latest haptic app has already been deployed.
Also, link process requires App ID and API Key. Go to the "Settings" tab, and check the App ID and API Key.
Import SDK Plugin
Get bHaptics Haptic Plugin in Unity Asset Store, and import the package into your Unity project.
For more information about importing the Unity package to your Unity project, follow the official Unity documentation.
Link the Haptic App
- In the toolbar, select "bHaptics" → "Developer Window".
- Enter your App ID and API Key from Portal, then click "LINK" button.
note
You can press "Forgot your App ID & API Key?" to visit Portal and retrieve the information.
- After successful certification, the application will appear on bHaptics Developer Window.
Browse App in bHaptics Developer Window
There are multiple tabs you can explore.
- Home: View the sample guide, and information about your application.
- Events: Browse and play the latest events you deployed from bHaptics developer portal.
- Documentation: Browse the documents about the SDK(including this site!)
- Latest Deployed Version: Check the version or refresh.
note
Ensure the version in the portal matches the version in the editor; if not, press refresh icon.
- Unlink: Disconnect between the game and the haptic app.
Add Prefab for Initialization
There is a prefab named "[bhaptics]" for initializing the haptic environment. It should be instantiated before using haptic-related functions. We highly recommend to place it at the first scene.
- Go to your first scene.
- In the Project Window, Go to "Assets" → "Bhaptics" → "SDK2" → "Prefabs".
- Add "[bHaptics]" prefab into your scene.
The component in this prefab uses the common Unity Singleton pattern with DontDestroyOnLoad. You only need to place it in the first scene, but it is okay to place multiple places since duplicates are automatically destroyed.
Update Android Manifest
If your Android Target API Level is 30 or higher, you need to update your AndroidManifest.xml
for the bHaptics integration in your game.
To check the project's Android target API level, Go to Project Settings → Player → Android settings(Android icon) → Other Settings → Identification → Target API Level. Refer the Unity manual for more information.
- Enable Android app manifest override. Go to Project Settings → Player → Android settings(Android icon) → Publishing Settings → Build → Custom Main Manifest. Then enable it if it's disabled. The directory of the manifest file is shown below.
- Open your
AndroidManifest.xml
file, which is usually located in theAssets/Plugins/Android/
directory. - Add queries element to the manifest file.
<queries>
<package android:name="com.bhaptics.player" />
</queries> - Update and Add Permissions to the manifest file.
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30"/>
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
After the process is complete, the manifest file should look like this.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
<queries>
<package android:name="com.bhaptics.player" />
</queries>
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
</manifest>
For more information, please refer to the following resources.
If you've activated Minify option, you should add exceptions to the Custom Proguard file (proguard-user.txt).
Further Reading
You're now ready to use the bHaptics haptic feature! Visit our Unity References page to play haptics in your game.
If you want to feel haptics right now, we provide a sample scene to explore the haptic events you can playtest. Go to "Assets" → "Bhaptics" → "SDK2" → "Examples" → "Scenes", and open "PlayParamSample" scene. You can play all haptic events with adjusting related parameters.