Production-grade, WhatsApp-style real-time chat for Unity
Drop-in chat plugin 1-to-1 messaging, groups, media, reactions, E2E encryption. Built on Firebase. Works on Android, iOS, and Desktop.
|
|
|
|
|
AES-256-CBC + HMAC-SHA256 ยท Per-conversation keys ยท Secure key exchange ยท Firebase Storage & Firestore security rules |
|
Import these packages from the Firebase Unity SDK:
| Package | Purpose |
|---|---|
FirebaseAuth |
User authentication |
FirebaseFirestore |
Real-time database |
FirebaseMessaging |
Push notifications |
FirebaseStorage |
Media uploads |
# Option A โ Package Manager
Window โ Package Manager โ + โ Add package from disk โ select package.json
# Option B โ Manual
Copy this folder into your project's Packages/ directory
Use the Setup Wizard: UnityLink โ Chat Setup Wizard in the menu bar.
Or manually:
- Create a
ChatManagerGameObject โ add theChatManagercomponent - Create a ChatTheme:
Assets โ Create โ UnityLink โ Chat Theme - Wire up UI panels โ
ChatListView,MessageWindow, etc.
cd CloudFunctions
npm install -g firebase-tools
firebase login
firebase init # Select Functions, Firestore, Storage
npm install
firebase deploy # Deploys functions + rules๐ก Try the built-in demo scene to see everything in action!
UnityLink โ Testing โ Create Dual Chat Scene โ Press Play
Two test users (Alice & Bob) will sign in automatically and chat side-by-side.
See Demo Scene below for details.
The plugin includes a fully self-contained dual-user chat demo in Samples~/DemoScene/.
| File | Description |
|---|---|
DualChatTest.unity |
Pre-built scene โ just press Play |
ChatManager.prefab |
Reference prefab with default settings |
DefaultChatTheme.asset |
WhatsApp-style theme configuration |
Option A โ Import via Package Manager:
Window โ Package Manager โ UnityLink Chat โ Samples โ Import "Demo Scene"
Option B โ Generate a fresh scene:
UnityLink โ Testing โ Create Dual Chat Scene
The DualChatTest component builds the entire UI at runtime โ no prefabs or manual wiring needed:
- Creates a split-screen with two chat panels
- Signs in Alice & Bob via Firebase Auth
- Both can send/receive messages in real-time
โ ๏ธ Note: Ensure Firebase is configured before running. See SETUP_GUIDE.md for detailed instructions.
UnityLink Chat/
โ
โโโ Runtime/
โ โโโ Core/ โ ChatManager orchestrator
โ โโโ Models/ โ UserData, ConversationData, MessageData, GroupData
โ โโโ Services/ โ FirebaseChatService, GroupChatService, StorageService
โ โโโ Sync/ โ ChatSyncEngine, ConversationRepository
โ โโโ Events/ โ Static ChatEvents hub
โ โโโ UI/ โ MessageBubble, MediaPicker, ReactionView, SearchView...
โ โโโ Theme/ โ ChatTheme ScriptableObject
โ โโโ Testing/ โ DualChatTest (self-contained demo)
โ
โโโ Editor/ โ Custom inspectors, Setup Wizard, Scene Generator
โโโ CloudFunctions/ โ Firebase Cloud Functions + Security Rules
โโโ Samples~/ โ Importable demo scene & assets
โโโ package.json
await ChatManager.Instance.SignIn("email", "password");
await ChatManager.Instance.CreateAccount("email", "password", "Display Name");
await ChatManager.Instance.SignOut();// Start a 1-to-1 chat
await ChatManager.Instance.StartConversation("otherUserId");
// Create a group
var group = await ChatManager.Instance.CreateGroup("Team Chat", "description", memberIds);
// Send media
await ChatManager.Instance.SendMediaMessage(convoId, filePath, MessageType.Image, "caption");
// Edit, Delete & Forward
await ChatManager.Instance.EditMessage(convoId, msgId, "updated text");
await ChatManager.Instance.DeleteMessage(convoId, msgId, forEveryone: true);
var results = await ChatManager.Instance.SearchMessages("query");ChatEvents.OnMessageReceived += (convoId, msg) => { /* new message */ };
ChatEvents.OnConversationsUpdated += (conversations) => { /* list changed */ };
ChatEvents.OnTypingStateChanged += (convoId, uid, t)=> { /* typing indicator */ };
ChatEvents.OnConnectionStateChanged += (state) => { /* online / offline */ };
ChatEvents.OnUnreadCountChanged += (convoId, uid, n)=> { /* badge count */ };// Group management
ChatManager.Instance.GroupService.AddMember(groupId, adminId, newMemberId);
ChatManager.Instance.GroupService.PromoteMember(groupId, adminId, targetId, MemberRole.Admin);
// Media
ChatManager.Instance.StorageService.UploadImage(convoId, userId, path, onProgress);
ChatManager.Instance.StorageService.DownloadFile(url, localPath, onProgress);
// Encryption
ChatManager.Instance.EncryptionService.Encrypt("hello", convoId);
ChatManager.Instance.EncryptionService.Decrypt(ciphertext, convoId);| Area | How |
|---|---|
| Colors & Fonts | Edit the ChatTheme ScriptableObject |
| Custom Backend | Implement IChatService for your own server |
| Custom UI | Extend or replace any UI MonoBehaviour |
| Encryption | Toggle _enableEncryption on ChatManager |
| Issue | Solution |
|---|---|
| Scripts don't compile | Import all 4 Firebase packages (Auth, Firestore, Messaging, Storage) |
FirebaseApp not initialized |
Verify google-services.json / GoogleService-Info.plist in Assets/ |
| Push notifications not working | Check FCM token in user document & Cloud Functions logs |
| Messages not syncing | Deploy Firestore rules; check Console for permission errors |
| Media upload fails | Enable Firebase Storage & deploy storage.rules |
| Group creation fails | Ensure Firestore rules allow isGroup documents |
| Requirement | Version |
|---|---|
| Unity | 2021.3+ |
| Firebase Unity SDK | 11.x+ |
| Node.js | 18+ (for Cloud Functions) |
| Platforms | Android ยท iOS ยท Desktop |
Built with โค๏ธ by UnityLink