GameMaker Now Supports Firebase


GameMaker Now Supports Firebase

GameMaker Studio 2 now supports various Firebase services such as Analytics, Cloud Storage & Databases through new extensions available on the Marketplace. You can download the extensions and read the provided manuals to easily implement Firebase features into your Android, iOS & Web apps (through SDKs) and other platforms (through a REST API for extensions that provide one).

The following extensions are now available to download for free:

  1. Firebase Analytics

  2. Firebase Authentication

  3. Firebase Cloud Functions

  4. Firebase Cloud Messaging

  5. Firebase Cloud Storage

  6. Firebase Crashlytics

  7. Firebase Firestore

  8. Firebase Realtime Database

  9. Firebase Remote Config

Let's now look at what functionality each extension provides.

Make sure to read the documentation PDF provided with each extension: it's accessible from the Included Files menu.

undefined

Firebase Analytics

This extension allows your app to send data to the Firebase Analytics server for various pre-defined events, and also allows you to create your own events for custom metrics.

Usage revolves around using FirebaseAnalytics_LogEvent() to send events to the Analytics server along with a JSON string.

Firebase Authentication

This extension is used to authenticate users using various methods of authentication, such as email/password combinations, phone numbers, and various identity providers such as Google, Facebook, Twitter, etc.

For example, for logging in with an email/password pair, you have functions such as FirebaseAuthentication_LinkWithEmailPassword() to link the current user to an email/password pair, FirebaseAuthentication_SignIn_Email() to sign in with an email/password pair, FirebaseAuthentication_GetEmail() to get the user's email, FirebaseAuthentication_ChangeEmail() / _ChangePassword() to change these details, and so on.

This makes it really easy to allow your users to create accounts for your app without having to create and manage servers and APIs for such a system.

Firebase Cloud Functions

This extension contains an example and a guide to help you set up a custom JavaScript backend to receive events triggered by other Firebase features and HTTPS requests. This is hosted completely on Google's cloud so you do not have to manage your own servers.

Firebase Cloud Messaging

This extension allows you to send messages and notifications from the Firebase Console directly to your app. You can use this to display a notification on the user's phone or receive the data directly in your app and manage behaviour in your app code.

The extension also allows you to subscribe the user to specific topics using the FirebaseCloudMessaging_SubscribeToTopic() function, so they can receive specific notifications for it.

Firebase Cloud Storage

This extension allows you to use Firebase Cloud Storage to store and download content generated by the user, such as images, audio, video and more.

Uploading a file is as simple as calling FirebaseStorage_Upload() and downloading one is simply done by calling FirebaseStorage_Download(). You can also get a URL to provide to the user with FirebaseStorage_GetURL() which they can share with their friends, and you can easily read a directory on the cloud by calling FirebaseStorage_List() to list all files and folders within the given path.

Firebase Crashlytics

This extension allows your app to easily report bugs and crashes which you can view and monitor from your Firebase Console. You are able to attach data with each report for easy debugging.

You can use FirebaseCrashlytics_RecordException() to log a non-crashing event and FirebaseCrashlytics_Crash() to log a fatal error. You can log messages during your game's execution by calling FirebaseCrashlytics_Log(), and any messages logged before an exception or crash will be visible in the Firebase Console.

This can be used with GameMaker's exception_unhandled_handler() function to automatically handle the collection of fatal errors.

The extension also allows you to enable or disable automatic sending of reports, so you can choose to disable it and send reports manually.

Firebase Firestore

This extension allows your app to store data in the Firestore database and serve it in real-time to your users. It also provides offline support so your app is functional regardless of the user's network quality.

The extension provides an SDK implementation for use with Android, iOS and Web, and a REST API for any other platforms. This extension uses a "method chaining" approach, so you always start your calls with FirebaseFirestore() and then chain methods onto it to build your request.

Here is a code example of uploading some data to the database:

var json = json_stringify({ name: "Hero", level: 100 });
listenerId = FirebaseFirestore("myCollection/newDoc").Set(json);

Method chaining keeps your code clean, which is especially useful when you are querying data from the database:

listenerId = FirebaseFirestore("myCollection").OrderBy("Points", "ASCENDING").Limit(10).WhereLessThan("Points", 50).Query();

Here we are loading a database collection, ordering it by a certain key, limiting it to 10 items, applying a condition to ensure the values are lower than 50, and then finally querying the database using these parameters.

Firebase Realtime Database

Realtime Database is similar to Firestore and allows you to store data in the cloud. The main difference is that unlike Firestore, Realtime Database does not store data as "collections" and "documents" (arrays and objects) but rather as simple JSON strings.

This extension also uses method chaining for its API calls.

Firebase Remote Config

Remote Config allows you to set up properties that you can change from your Firebase Console. Your app can then read such properties from the server and update its functionality or visibility accordingly, meaning that you can make changes to your app without having to push an update or change any app code.

You can use functions such as FirebaseRemoteConfig_GetDouble() and FirebaseRemoteConfig_GetString() to read the value of a key, and the FirebaseRemoteConfig_GetKeys() function to get all keys set for the app.


Make sure to check out the extensions on the Marketplace, and hope you will have fun with them!

Happy GameMaking!


Written by Gurpreet S. Matharoo

Technical Writer at GameMaker, Gurpreet creates documentation and tutorials, to make game dev easier for you. He loves using the computer to bring new things to life, whether it's games, digital art, or Metal music.