Simple and powerful hCaptcha integration for Unity Android games and apps.
- ๐ฎ Drop-in Integration - Import and use in minutes
- ๐ป Invisible Captcha - Seamless user experience
- ๐ง Automatic Setup - Gradle configured automatically
- ๐ฆ Pre-built AAR - No Android Studio required (Unity 6+)
- ๐ฏ Simple API - Easy C# interface
- ๐จ Two UI Examples - OnGUI test scene + Canvas-ready prefab
- ๐ MIT Licensed - Free for commercial use
- ๐ Open Source - Full source code available
Download the latest HCaptcha-Unity.unitypackage and import into Unity:
Assets โ Import Package โ Custom Package โ Select downloaded file
- Sign up at hCaptcha.com (free)
- Create a new site
- Copy your Site Key
After importing, Unity must use the included Gradle templates:
Edit โ Project Settings โ Player โ Publishing Settings โ Build- Enable BOTH:
- โ Custom Main Gradle Template
- โ Custom Gradle Settings Template
Without these, the build will fail! These templates configure JitPack repository and hCaptcha dependencies.
Then add to scene:
- Drag
Prefabs/HCaptchaManagerinto your scene - Select the prefab in Inspector
- Paste your Site Key
- (Optional) Drag
Prefabs/TestUIfor instant test button - Replace Unity's generated templates with package templates:
- Copy
Assets/HCaptcha/Runtime/Plugins/Android/mainTemplate.gradleโAssets/Plugins/Android/mainTemplate.gradle - Copy
Assets/HCaptcha/Runtime/Plugins/Android/settingsTemplate.gradleโAssets/Plugins/Android/settingsTemplate.gradle - Overwrite when prompted
- Copy
using UnityEngine;
using HCaptcha;
public class LoginManager : MonoBehaviour
{
void Start()
{
HCaptchaManager.Instance.OnSuccess.AddListener(OnCaptchaSuccess);
HCaptchaManager.Instance.OnFailure.AddListener(OnCaptchaFailure);
}
public void OnLoginButtonClick()
{
HCaptchaManager.Instance.Verify();
}
void OnCaptchaSuccess(string token)
{
Debug.Log("โ Captcha verified! Token: " + token);
// TODO: Send token to your server for validation
AllowLogin();
}
void OnCaptchaFailure(string error)
{
Debug.LogError("โ Captcha failed: " + error);
ShowErrorMessage("Verification failed. Please try again.");
}
}Or connect directly in Unity UI:
- Select your Button
- OnClick() โ Drag
HCaptchaManagerprefab - Select function:
HCaptchaManager โ Verify()
HCaptcha/
โโโ Runtime/
โ โโโ Prefabs/
โ โ โโโ HCaptchaManager.prefab # Main captcha handler
โ โ โโโ TestUI.prefab # Ready-to-use test button
โ โโโ Scripts/
โ โ โโโ HCaptchaManager.cs # High-level API
โ โ โโโ HCaptchaUnityBridge.cs # Android bridge
โ โโโ Plugins/Android/
โ โโโ unithhcapt-lib.aar # Pre-compiled library
โ โโโ mainTemplate.gradle # hCaptcha dependencies
โ โโโ settingsTemplate.gradle # JitPack repository
โโโ Editor/
โ โโโ HCaptchaSetup.cs # First-time setup helper
โโโ Samples/
โโโ TestHCaptcha.cs # Example OnGUI test scene
| Requirement | Version |
|---|---|
| Unity | 2023.3 LTS or newer |
| Platform | Android only |
| Min SDK | API 22 (Android 5.1) |
| Target SDK | API 34 (Android 14) |
| Gradle Templates | REQUIRED (Custom Main + Settings) |
- Pre-built AAR works out of the box
- Enable Custom Gradle Templates and replace with package templates (step 5 above)
The included AAR is compiled with Java 17. Unity 2022.3 uses Java 11, causing build errors.
Solution:
- Clone the Android library source
- In Android Studio, set Java 11:
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}- Rebuild AAR and replace in
Plugins/Android/
Press Play โ You'll see "Platform not supported" (expected - hCaptcha works only on Android)
- Build APK:
File โ Build Settings โ Android โ Build - Install on device
- Run app and press verify button
- Complete captcha
- Check logcat for success token
Want to customize the Android library?
See Android/README.md for build instructions.
"Platform not supported"
- Normal in Unity Editor - hCaptcha only works on Android devices
"Site Key not configured"
- Set your site key in HCaptchaManager Inspector
Gradle build fails with "keepUnitySymbols.gradle does not exist"
- Enable Custom Gradle Templates in Player Settings (see setup step 3)
- Replace Unity's templates with package templates (see setup step 5)
"D8: java.lang.NullPointerException" or class version errors
- Unity 2022.3: AAR needs Java 11 rebuild (see compatibility section above)
- Unity 6+: Make sure you replaced templates (step 5)
"compileSdkVersion is not specified"
- Replace Unity's generated templates with package templates (setup step 5)
Methods:
Verify()- Start captcha verificationReset()- Reset captcha state
Events:
OnSuccess(string token)- Fired when user passes captchaOnFailure(string error)- Fired on error or user cancellation
Properties:
Instance- Singleton instance (auto-created from prefab)
Contributions welcome!
- Fork the repo
- Create feature branch:
git checkout -b feature/amazing - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing - Open Pull Request
MIT License - see LICENSE
This project uses hCaptcha Android SDK (also MIT licensed).
- hCaptcha - Bot protection service
- hCaptcha Android SDK - Native Android SDK
- ๐ Report Bug
- ๐ก Request Feature
- ๐ฌ Discussions
โญ Star this repo if you find it useful!
Made with โค๏ธ for Unity developers
