My Unity game - Couchbase Lite roadmap & gotchas


This is primarily addressed to @borrrden @zgramana & @sweetiewill who have been very helpful on Unity questions. Since you guys have messed around with the relationship between couchbase and Unity, I’d like to get started on the right road, and learn from your experiences.

I chose Unity because I wanted to code the game once and then deploy to any device.

I chose Couchbase because my game is trivia-based which means that the database IS the game… and Couchbase handles the offline-mode + sync-to-cloud interaction the right way. (The #2 option was Parse, which does not support LocalDataStore on Unity… plus the LocalDataStore has a weird #pin method of persisting data offline, which means a lot of bandwidth to constantly fetch-and-pin my whole database over and over. The #3 option was Firebase, which required major workarounds to integrate into Unity and they had no timetable for making any Unity Plugin or SDK.)

So let’s make this work.

I want to deploy to Android phones, Android tablets, iOS phones, iOS tablets, and a WebPlayer (for the browser of desktop computers, ChromeBooks, etc.). So let’s talk about how Couchbase Lite integrates in these areas… specifically using REST API or the Native API.

Deploying to Android from Unity3D
@borrrden says that it might be difficult to make the REST API work because Android shuts down things when the app is backgrounded. Might be able to work around this with a “service” instead of a regular app. Has anyone been able to do this?

I don’t think anyone’s discussed using the Native API on Android. Is anyone aware of any issues with Native API on Android?

Deploying to iOS from Unity3D
Has anyone successfully done this with either REST or Native API? @borrrden mentioned he’s working on an IL2CPP issue, so I’m guessing that we’re waiting on that…

Deploying to WebPlayer from Unity3D
The space-shooter readme file says “This will not build for web player. Web Player puts large amounts of restrictions on the available API, some of which Couchbase Lite makes use of.” That implies that Space Shooter would actually work on all the other platforms. Does it?

@sweetiewill suggested using the REST API to get around this limitation. Do the rest of you agree that Native API simply will not work on WebPlayer? Has anyone actually successfully built a WebPlayer + cbLite app? How about WebPlayer using REST directly to my cbServer in the cloud?

Again, I’m looking for a code-once and deploy-on-all solution. It sounds like Native API won’t work on WebPlayer. Can the REST API work on all of them? Could we get a space-shooter-like demo using REST API that does actually work on Android, iOS, and WebPlayer?

Very grateful for your assistance. Any tips you guys have are most appreciated.

Kind regards,

FYI the reason I said that is because you were talking about replicating between two apps on the same device. Let’s start with some basic facts: The app needs to be running in order to process REST requests. I know Android is much less strict than iOS about what you can do in the background but still I’m sure it doesn’t arbitrarily allow things running permanently in the background without some setup. I’m pretty sure on iOS this will not be possible due to backgrounding restrictions.

As far as the IL2CPP issue, I’m still waiting for a response from Unity on that. Using Mono works for deploying to device, but it’s not acceptable for the app store.

Space Shooter will work on Standalone, iOS, and Android (parallel to what we support outside of Unity).

Anyway I think you are confused about the term REST API. It doesn’t necessarily mean the “listener” component. What @sweetiewill was referring to was making REST calls to sync gateway from the web player build. The listener component depends on the Couchbase Lite component so you won’t be able to use it in web player anyway. So what he was suggesting was to store the data in another way on web player and use REST calls to interact with Sync Gateway from your web player build.

Another possibility is investigating PouchDB which is similar to Couchbase Lite, but written in Javascript. It is designed to interact with backends that implement the CouchDB sync protocol (which Couchbase Lite / Sync Gateway does). I don’t think anyone has ever tried running it inside of Unity before, but maybe it is worth a shot.

Again, I’m looking for a code-once and deploy-on-all solution

Aren’t we all? :wink:

Thanks Jim! Very helpful.

PouchDB looks interesting…

a) Are you saying that Pouch might work for the WebPlayer without using REST?

b) Surely, then, I can also use Pouch for Android and iOS. Am I giving up any features of I chose Pouch instead of cbLite in my Android build?

I don’t think anyone has ever tried running it inside of Unity before, but maybe it is worth a shot.

Other than space-shooter, I’m pretty sure I’d be the first Unity game using cbLite, too. So either way, I’m a pioneer. B-)

Define “without using REST”. PouchDB itself, of course, uses REST calls to communicate with its remote replication endpoint. PouchDB is designed for browser / Javascript so I don’t know how far you’d get trying to incorporate it into your iOS / Android project. I’m not terribly familiar with javascript web development (honestly I’ve tried to avoid it as much as possible)

Thanks again, Jim. I think it’s finally coming together in my head.

My new plan will be to make the Android build first using cbLite and Native API. Hopefully by the time that’s done, the IL2CPP thing will be ironed out and I can then work on the iOS build.

Third will come the WebPlayer, and I’ll have to decide to try Pouch or just query my cbServer directly with that one.

I’ll get started and keep you updated.

Kind regards,


Did the IL2CPP issue ever get figured out?

Kind regards,