Advanced Godot | Interacting with Firebase from Godot on Android

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

This post appears to be a direct link to a video.

As a reminder, please note that posting footage of a game in a standalone thread to request feedback or show off your work is against the rules of /r/gamedev. That content would be more appropriate as a comment in the next Screenshot Saturday (or a more fitting weekly thread), where you'll have the opportunity to share 2-way feedback with others.

/r/gamedev puts an emphasis on knowledge sharing. If you want to make a standalone post about your game, make sure it's informative and geared specifically towards other developers.

Please check out the following resources for more information:

Weekly Threads 101: Making Good Use of /r/gamedev

Posting about your projects on /r/gamedev (Guide)

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

👍︎︎ 1 👤︎︎ u/AutoModerator 📅︎︎ Apr 19 2021 🗫︎ replies

Hey guys I'm Mitch I created the FinePointCGI YouTube channel and I made a tutorial about integrating firebase into your Godot game. I thought it might be useful for you guys for me to throw it over here. If there's anything you guys want me to cover let me know! Also mods if this isn't okay let me know and I won't do it again!

Thanks Mitch

👍︎︎ 1 👤︎︎ u/finepointcgi 📅︎︎ Apr 19 2021 🗫︎ replies
Captions
[Music] hey guys this is mitch with finepoint cgi and today we're going to talk about firebase support for android inside of godot now the reason why this is very specific to android is because if you do firebase support outside of android it's a completely different plug-in and it's completely different setup so i'm going to be coming out with a tutorial hopefully next week about that but if that's what you guys are looking for then this tutorial is definitely for you guys so we're going to go through the process of downloading the plugin hooking it up we're going to go through authenticating with google and we're going to go through the process of throwing data out into the cloud and pulling data back and also finally we're going to talk about doing push notifications with firebase so it's a lot of information and there's a lot of stuff to get through so let's go ahead and get started so the first thing that we're going to talk about is we're going to talk about what firebase is so firebase is a api that allows you to do all sorts of really cool analytics without needing to code it yourself so for instance it allows you to use the cloud firestore which is a document based database so you can actually go out and store data and things like that it allows you to authentication so if you want to do google authentication or facebook or twitter or uh just email based authentication that's a great way to go about it it allows you to do crash analytics and google analytics so you can actually get you know if something crashes like how why did it crash how did it crash things like that and finally you can actually use it for cloud messaging and stuff like that so it's a really cool cohesive ecosystem that basically solves a large majority of problems for people who have a small app so if you have like a a small to medium sized app firebase is a good starting point for you to build a community around your app so if we go ahead and look at the pricing i'm just going to show you guys this real quick um as you can see like if you have under a 10 000 users a month that are authenticating to your system that is all free and same thing with store data as long as you keep your data under a gigabyte of data and under 20k 50k and 20k a day read writes and deletes like a lot of this stuff is totally free so like i said if you have a really small app or a medium sized app this is an awesome little system here so first let's go ahead and set up our godot project so let's go ahead and open up godot okay so now that we're in godot what we're gonna do is we're gonna click user interface we're gonna go ahead and hit ctrl s to save it and we're gonna call it tutorial firebase example all right you guys can call whatever you'd like but i'm gonna call that we're gonna go to project install the android build template and as a prerequisite you need to have gone through my doing custom modules with godot i believe i did that in one of my videos i will throw it in the link in the description below as a prerequisite to this tutorial so you can have all this set up for you but go ahead and install that and then we're going to go to project we're going to go to export add android and we're gonna say yup go ahead and use custom builds because we need that to be on all right now what we're gonna do is we are also going to say project project settings we're gonna set our default scene over here to our tutorial firebase example so that way it when it runs it goes ahead and just runs the firebase scene so we're gonna hit close we're gonna right click on this and open in file manager something that we're gonna need to keep open is this little file manager with all of our information here because basically we're going to be living inside of this little folder here inside of probably visual studio code so what we're going to do is we are going to we're going to go ahead and take a look at our plug-in here so this is the plug-in that we're going to be using this is the godot 3.2.2 android plug-in for firebase now something of note if you are using this plug-in you cannot target anything other than android with this plug-in now the reason why we're using this plug-in specifically for android is because it has a lot of cool support for like push notifications and things like that stuff that you wouldn't get if you were doing the generalized plug-ins that exist out there so that's just something to keep in mind so we're going to do is we're going to go ahead and download this code now i've already done that here mult actually a few times because i've recorded this tutorial a few times but uh i'm going to go ahead and hit cancel and i'll just go out to my downloads folder here and you can see that i have it so we're going to do is right click and extract it and it'll extract out into this little folder here so what we're going to do is we'll open up our downloads and you'll see that we have a firebase release and a firebase release aar we're going to go ahead and copy that and we are going to open up our godot android firebase project location and go to android plugins we're going to go ahead and paste that in here and what that's going to do is it's going to set up godot to understand that we're trying to use the firebase plugin now what we're going to do is we're going to go back one we're going to go to build we're going to right click we're going to say new folder and we are going to say assets and we are going to go into there we are going to go back to our plugin directory we are going to copy our godot firebase config and we're going to go ahead and paste it right here so now we got all that set up we need to go back to our build directory and i'm just going to go ahead and open this up with visual studio code like this folder so we're gonna i'm gonna go cmd and i'm gonna do a code dot and that's gonna open this folder up in visual studio code so that i can actually see and change these things easily so we're going to go and open up our build.gradle right here and we are going to it looks like line 18 we're gonna create you know carriage return and we are going to type class path [Music] com.google.gms colon google dash service says 4.3.3 all right now what that's going to do is it's going to tell gradle that we want to include the google uh services into our project and now we need to go find our chunk global begin which is right at the bottom and we are going to add a apply plug-in colon [Music] com.google dash services [Music] let's make sure we spelled it wrong i missed the g so we're going to save that and we are going to go into our assets folder godot firebase and this place is where you say i want analytics i want admob i want you know admob you know stuff in here i want authentication i want firestore storage so we're going to do is we're going to go ahead and shut off admob and we're going to go ahead and shut off authentication because those are going to require a lot more setup and i just want to show you guys how to do other things first and then we'll turn those on in a minute so go ahead and save that and now after all that setup we still have a little bit to go we're going to go to android build config.gradle and we need to change our minimum sdk to 21. now minimum sdk is basically the minimum api level that you have access to in android so as android has grown the api level has gone up to add additional features and things like that that developers can make use of so minimum sdk of 21 is uh making it so that anybody who has uh android kitkat and pat and and before cannot download your application so that's just something to keep in mind that your api level actually does matter so in this case it's lollipop up so lollipop marshmallow nougat oreo pie in 10 and 11 for android 10 and 11 and uh that's just something to keep in mind so that you're not removing parts of your audience that may have older phones in this case i mean it's it's a pretty new phone so or a pretty old phone i mean android lollipop came out in 2014 so it's it's a fairly old operating system and i not very many people use it anymore so we should go ahead and set up our firebase so let's open up the firebase console here so if you go to console.firebase.google and you already see i created a test project but i'm going to go ahead and add a project and we're going to call it [Music] godot firebase test project you guys can name it whatever you'd like but i'm gonna name that go ahead and hit continue i'm gonna go ahead and enable um google analytics so that way it allows us to do in-app messaging which and cloud messaging which allows us to do a lot of engagement stuff so we can actually send messages to your cell phone so go ahead and hit continue and go ahead and select an account and just use the default account for firebase and click create project now what google is doing or what firebase is doing right now is it's going ahead and creating you all of your stuff that you need to uh interact with it so basically it's creating like an api and it's compiling it and it's setting up all of your resources and it's setting up analytics and all that stuff is just building it all for you so now it's created and we're going to go ahead and click continue and now we are in our test project now one of the beautiful things about firebase is everything's separated so ios android and web are all separate from each other so your android people could pull like let's say you have a scoreboard and you want your android people to be able to pull from your web people's scoreboards you can actually just set that up right it takes almost zero effort on your part you just say yep this connects to the same database and it's done so that's one of the beautiful things about firebase so we're going to go ahead and click android and we're going to say com dot fine point cgi goodness can't type my own name dot firebase test app we're going to copy that and we are going to click register app so what that's going to do is it's going to allow us to download this googleservice.json so let's go ahead and download that i already have one but they're unique to your project so go ahead and hit save yes i want to replace that and i'm going to close that so i don't have to look at that anymore and we're going to click next none of this matters to us at least not in this specific case and next step hey you're all set you're good to go so go ahead and continue to console now if we go back to godot here and we go to project export and we scroll down just a little bit you'll see this little package unique name we're going to go ahead and paste our name here so that way they may so that way the name on google firebase and the name on the app is the same so that way firebase knows hey this is the same application while we're in here let's scroll uh up and turn on our firebase plugin so that way we just have it so that way it's just done go ahead and click close and now that we have all of that we need to go ahead and open up our downloads folder go back to our downloads folder and copy our google service json file and we are going to go into our project we're going to copy this to android build and paste it right here so that way it's part of your building system i know that this is really complicated and just a pain in the butt but it's really worth it once you get it going i know that usually when people say that it's probably not worth it but it really is um once you get it working it's it's really easy to use so now at this point that should be all of our setup we need to do our basic firebase integration so things like storage and push notifications all that should be handled especially since if we go ahead and we look at our firebase configuration we did shut off admob and authentication so that should stop our some of the build errors that we're going to run into it should stop those from occurring hopefully and if not then we'll we'll burn that bridge when we get there so what we're gonna do is we're gonna right click control node and we are going to rename this as master control node and we are going to right click attach a script we're going to call this master firebase control first things first we need to make a global variable so var firebase so that way we have it it's equal to null and we are going to go ahead and load that singleton so if you don't know anything about plug-ins basically uh whenever you load in a plug-in it's a singleton for the entire project so you can actually load it anywhere in your project so if you just hit if engine dot has underscore singleton and then quote firebase then i want to go ahead and load it so firebase is equal to engine dot get singleton capital f firebase so what we're doing is we're saying hey if you have this go ahead and load it and the reason why we do this is because if you don't have the singleton it's going to crash your application well it'll throw an error at least and you don't want that right you don't necessarily want it to fail loudly you might just want to say oh well they're probably just in testing mode or something right so we don't want you to just outright fail the application because you can't find a singleton so i always like to do a print and just say hey you know um loaded firebase and then i'm gonna say hey if firebase so if firebase got loaded successfully then i want firebase dot init so that way it initializes it and i'm getting my instance id so what that's gonna do is it's gonna say hey let's build firebase let's go ahead and initialize it with our firebase instance id so that way we can authenticate with the firebase servers so now from here let's go ahead and set up our cloud messaging so that way we can actually uh shoot down a little message down to our android application and that will allow you to send messages to people so you could actually say hey try our new insert whatever right so let's go ahead and add that so let's do firebase dot cloud messaging underscore subscribe underscore to topic and we're in normally you would put in whatever topic name you want so i'm just gonna put topic name but you can call it whatever you want that allows you to to specific uh specifically targets audiences so if you were to put like you know my app name android right and then in firebase you can say send a message to just the people that are in that specific topic or you could send it to a generalized audience you could say send it to everybody so everybody has that so now that we're at this point let's go ahead and save always and i'm going to grab my phone and plug it in and let's see if we have everything set up odds are we're going to have a couple of compilation errors but let's find out so now that i got my phone plugged in let's go ahead and click the android icon up here now if you don't have this android icon you need to enable developer mode on your phone and to do that just go into your settings go into your about android and just keep tapping the system version and that'll give you into developer mode and then you can enable debugging and that'll basically run all of this so let's go ahead and hit that button and it's going to go ahead and build it's going to take some time and if i run into an error i'll stop and let you guys know all right so it looks like we got an error of some kind so judging by looking at it our android manifest says hey it uses 18 so let's go ahead and take a look at that real quick i think i found it it looks like i just didn't save so let me let me change that control s and then let's go ahead and retry our build and let's see what it does all right it looks like it crashed on us so let's see why so let's do an a d b let me put this in the center here adb log cat let's pull all of our logs you'll see that's going to go absolutely insane here and let's reopen the application you're going to see it freak out for a bit and it looks like it just immediately crashes so let's go ahead and take a look as to why paste it ctrl f and we go godot and let's go to the bottom here let's take a look at what in the world happened here so you can see that we have a timeout here let's change this to a log so we get some coloring we scroll up uh see the mobile ad sdk so it looks like it wants us to add mobile ads well that's a good thing because we're already gonna be adding ads to this so i'm not concerned so what we're gonna do is we will go ahead and do that right now might as well right so we're in our godot firebase project let's scroll down here and do admob and you'll see that it says hey uh admob yay already integrated the sdk link your admob link your apps in admob simple enough right so let's go ahead and click that and you can see my various test apps here i actually have one called firebase test app already created but i'm going to add a new one we're going to say android and no it's not going to be on the the store as of right now um they're going to so we're going to click no and then we're going to hit continue and our app name is our same app name inside of here so project export and copy our little unique name here and come up here and paste it hit add app and that's going to go ahead and add our app now we're going to need to go ahead and set up our ad units so select a banner and just call it firebase test app banner there we are and i'm just going to go ahead and copy that so i can just use them create me an ad unit and now you can see it gave us a bunch of uh unique little identifiers here so we're gonna need to go ahead and copy this and if you don't want admob you'll need to disable it inside of your project by the way so i can show you guys how to do that but since we're going to be showing it anyway i'm just going to go ahead and add it so what we need to do is we need to go to our project location if you remember that we have this and we open up our assets folder and our godot firebase configuration you see there's an app id here so let's go ahead and paste that in here and then we need to give it a banner id so let's go ahead and grab our banner id from here to here awesome now that's done let's click done and let's add another ad unit and let's do an interstitial ad and let's call it firebase test app interstitial let's create that ad unit let's go ahead and grab this little interstitial ad id and paste that go ahead and hit done create another ad unit and create reward and we're going to call it firebase test app reward click create ad unit and of course copy this and paste it inside of here there we are go ahead and click hit control s admob is set to true now because we want it now and for us to use admob we need to go to our android manifest so find that and find where it says chunk application begin right here and go ahead and add in metadata and type android colon name is equal to quote com dot google dot android dot gms dot ads dot capital a p p l i c a t i o n underscore id and then we're going to add android colon value make sure you spell everything correctly quote and here we need to add our android app id here let's go ahead and copy that paste that in there and do slash uh bracket here awesome so now that that's done we can now authenticate with our admob system out on the web now if you don't want this now if you don't want this what you're going to need to do is you're going to need to change and i'm not going to but i'm just going to show you how to do it if you go into your your plug-in and your release gdap here's all of your remote dependencies here so you can actually go in and pull all of these out and that will pull out that section of code from your project so if you didn't want admob you can go ahead and just pull like these ones out and it'll just rip them out of your project so you don't have to worry about them so if you don't want to set up admob just go ahead and do that i'm going to set up admobs because it's part of the tutorial but if you don't want to just go ahead and remove those same thing with anything else just don't ever remove analytics if you do that firebase gets very angry but you can pretty much remove anything in here and it should just remove it from your project so now that we got that set up let's go ahead and try to run our project again so let's go ahead and click on our little android guy and let's see what it does it may or may not pass we'll see how it goes because there's there's a little bit of finickiness here that we're gonna have to work around uh we might need to re-download our google um json file so that way we can update firebase on our machine to know like hey you know we have analytics or uh we have um admob set up but i don't believe we need that specifically right now but let's just make sure all right as you can see it did actually load so that's a good sign so now that it loaded let me show you one of the coolest features of firebase let me close my project and completely kill it now that i'm sitting at my home screen let me open up our google proj or our firebase project and let me scroll down to cloud messaging here if i click on that and i go send your first message opera let's say for title firebase test message enter notification text this is a test message and you can actually put in a notification image if you want to upload it and it tells you hey you need to upgrade to the blaze plan to do that i'm not worried about it but you can actually go ahead and send in a notification message so if i wanted to i could probably just paste in my image address and that should send that now if i hit next it'll ask me a target so target if a user is in my app so if you are in my application i'm firing you a message schedule it right now i can set it to whenever i want schedule daily custom things like that but i'm going to go ahead and send it now and i can actually set goal metrics and things like that like hey i want you to subscribe or i want you to uh do an in-app purchase or convert you know and try to download something right and you can add analytics labels if you'd like but i'm not going to do any of that and these are all optional fields but you could add in like sound so that it you know pings their machine things like that or you could have a special notification channel and this is the the notification channel that i was talking about the topic that i was talking to you guys about but now if i say review and i say yep publish it should send it out to my phone so we're gonna let that go let's see if we get a message all right we just got a message so if we scroll down you'll see this is a firebase message and you can see it's got my little user avatar which is kind of cool and that is how you send messages and if they touch this it will load your application so it allows you to reach out to touch your customer and have them interact with your application in a way that you never could before which is awesome right so now that we got that working what we're gonna do move neatly along to setting up admob so let's go ahead and set that up real quick so if we come in here and we go ahead and right click add a child note a button and then we're going to move this button down over here and we're going to control duplicate that button twice so let's pull this down and let's pull this down we're going to call this one banner add we're going to call this one reward add we're going to call this one interstitial ad so right click rename i n t e r s t i t i a l add all right so now we have those all named let's go ahead and click node on button up and we'll go ahead and connect those so on button up connect it to my master node here alright now that we have that set up let's go ahead and do our banner ad first so let's do on banner ad up do firebase dot admob underscore banner underscore show is equal to true so that's going to show our banner ad now on reward ad we want firebase dot admob and actually i'm just going to go ahead and copy this because there's no sense in not copying it is equal to false because you can't show a banner ad if you're showing other ads or you can't i guess you can't show other ads if other ads are being shown so for instance if you're trying to show a reward ad you can't show a banner ad if you're trying to show a banner ad you can't show a reward ad it doesn't allow for that google frowns upon that kind of stuff so just don't do that so on reward ad i want firebase dot admob underscore rewarded underscore video underscore show awesome now what we're going to also do is we're going to say firebase dot interstitial you can never spell it underscore show so now for this one we need to implement a callback right so if you're getting giving them a reward video you want to know that they watched the reward video right so what we can do is we can say funk underscore on underscore firebase underscore receive underscore message and we're going to say tag comma whoops no caps tag comma space from comma space key comma space data and we're going to go ahead and print all of that information so let's just copy this so that way we have that and what this does is and everything will be tagged with firebase if it comes back from is the module that it comes back from so for instance if you're doing something like firestore or if you're doing something like uh admob it'll come back with from key is the uh section of that module for instance if it's like a banner or a reward video right you can actually see uh what it's from so for instance if i were to let's say i want to do my reward video callback right so let me go if tag is equal to firebase and if it's from if it's from admob and finally if it's he is equal to reward video or rewarded video then i want to print that it um if that they watched the reward awesome so now i can actually take this little call back here and i can know if they watch the reward video let's go ahead and save this and throw it out to my android and we will have to look at the logs so we're gonna have to make sure that we're connected via adb if you haven't done that you have to do that and let's go ahead and run this and let's see what happens all right so you can see that we have three buttons here it looks like weirdly enough they're really hard to read so we're gonna have to change some of our scaling here but let's go ahead and touch one of them yeah it's way too small for me to be able to touch it so let me go ahead and fix that real quick so let's go in here and let's go to project project settings scroll down to window and change our stretch mode to 2d and our keep width close and then go ahead and fire that off and you can see our our admob video our admob banner ad just got fired so we know that it at least is working unfortunately the buttons are so small i can't click on it so let's let's go ahead and just re-fire that application off all right that's much better it's much bigger so now let's go ahead and hit our interstitial ad i believe it is the next next one's reward ad so if we hit that see if we got any bugs or anything did it not load properly [Music] all right there you go now you can see that we actually got our reward video so that's great so now we have interstitial but if we click on that it doesn't seem to be working so let's take a look as to why it's probably something i've done on my end incorrectly so let's see first things first if we look at our reward video you can see that if we look for godot here all right let's go back ah see we got a bug here script error invalid call non-existent interstitial show so i misspelled this most likely that's probably what it is so let's go ahead and take a look ah i forgot admob underscore interstitial let me see if i spelled that correctly i'm just going to go ahead and paste this yep it's spelled right okay it's because i missed admob most likely so we'll go ahead and rerun this but while we're here i want to take i want to kind of point out if you look you can see that it loaded our ad mob video our interstitial failed because we don't know how i don't know how to spell to save my life and if we come up here you can see here we got back admob reward video reward amount is 10 reward type coins status earned and we got our unit here so that's awesome what that means is we've we can reward the user here right so for instance that's from what this is so we can actually type in watched the reward and it probably will come up i see so somewhere we have a little bit of an issue here from admob ah capital m that'll get you all right that'll get you so the issue is that i didn't have a capital m here i lowercased my m so it didn't get that far so what we can do since we now know that our callback is working properly right we know that we're getting our stuff there watching the reward video what we could do is we can come up here right click add a child note and put um we can put a rich text label let's go ahead and put that i don't know over here somewhere and let's call this reward amount and we'll say zero and let's come over here and say dollar sign rich text label which actually i'm going to rename that because i hate that name let's get rid of that let's right click let's rename this as or maybe it's not going to let me there we go rename this as reward counter let me just copy that and dollar sign reward counter dot text is equal to print [Music] is plus equals one and we're going to cast that as a string so str string now i'm going to need to create a variable up here so var current reward amount so let's just copy that is equal to zero there we are so now what that's gonna do is that's going to allow me to fire or that is going to allow me to set my current reward amount plus equals one and cast it as a string and then change my text all right now what we're going to need to do is we're going to need to add right here to say what did i say for this reward counter i said reward amount yeah so we'll do is we'll grab this section of that go back to our little script here reward amount space quote oops plus and there we go so what that's going to do is when we get our reward back we will have our reward amount in the upper right hand corner of our screen now again this is just to kind of show you like all the different features here so now that we have all of this set up let's go ahead and set up our scoreboard and let's set up our database so first things first what we're going to need to do is we're going to open up our godot firebase here and we're going to need to scroll up and do firestore database you can see hey is cloud firestore right for you or is real time right for you and basically from what i've found and i've had conversations with people about is real time database is the older version of firestore database so eventually it's going to get overwritten with cloud firestore so let's just go ahead and use cloud firestore so we're going to create a database and we're going to set it up into test mode in production mode it's um just needs some security changes you guys can go ahead and change those but right now and you can see here here's the different security stuff here so we'll go ahead and just use test mode so we can go ahead and test this so click next and we need to set a location which i don't think yeah they're saying that us central is closer to us so we'll go ahead and do that and we'll enable that what that's going to do is it's going to go out to the google servers and actually set up our database and kind of house all of our data in a nice little spy space on the web for us so it's super great because it just makes things just i mean it's just so easy you know [Music] all right so we're going to start a collection we're going to call this collection scoreboard [Music] actually we'll do that scoreboard next and we need to add a document so let's add a document call it [Music] fine point cgi field we'll say id it's a number id of one and then field name string and we'll say find point cgi and we'll add one more field and we'll say score and we're going to change that to a number we're going to say i got 500 points all right so now we've literally just created our database created our entire collection and a document so the way that this database operates is you have collections which is like a collection of data document which basically houses your fields of information so think of it kind of like um kind of like honestly like a document right you can have a document that has this text in it and that's the data that you're going to get back in this document and you can also do sub collections if you want inside of here so you could go scoreboard fine point cgi uh slash you know weapons right and you can have all the weapons and all the stats and all the things inside of this collection here but in this case we're gonna do something simple so we're just gonna allow for this all right so now we're gonna go back to our android firebase demo project and what we're gonna do is we're going to first load all of our scores so firebase dot buyer store underscore load underscore document we're going to say quote scores or scoreboard i believe it's scoreboard let me see yep scoreboard so scoreboard you can see firebase isn't declared i probably spelled it wrong as always there we are and now we need to come down here to our receive message we need to say if from is equal equal quote buyer store then i want to say if we have data then i want to say var json data is equal to json.parse data and what this is doing because the data that's going to come back from our firebase is json data we need to parse that data because it's going to come back from an api so we need to actually parse that data into into an object right so now what we're going to do is we're going to say uh let's see we need to write it into an object so let's go ahead and do a little bit of housekeeping here and build out ourselves a small scoreboard so let's see where do i have space okay so we have space over here somewhere so let's go ahead and add a child node and just node 2d and let's right click this add in a v box container let's just make it i don't know decent size we'll put it over here something like this i think will work and then underneath that we're gonna right click add a child node add in a h box container and we're gonna call this a score row all right and underneath that we're going to and actually let's pull that out up here for now let's expand this so we can actually see what's going on first and add any child node add in a a rich text label and let's control duplicate that twice name the first one id name the second one name and name the third one score awesome so now what we're going to do is we'll set you know id of one name test and score of 500 let's say now you can see here we can't actually see them so what we need to do is we need to set our minimum size to a proper size here so let's set this to i don't know 50 let's say that might work and then let's set our minimum y size to at least 10 so that way it's guaranteed that if we set this down to something like let's see 15 there we go so we'll say minimum size is 15 here awesome so that way this is all set up properly here now if we put this score row underneath our v box container when we duplicate this you'll see that we have more more rows here see so we'll go ahead and delete these we don't need them we'll right click this score row here and we are going to save this branch as a scene as scorrow.tscn awesome now it's saved so now what we can do is we can click on this little um clapper and open it up in the editor now what we need to do is we need to set up a small function inside of here so we'll attach a script here called scorrow.gd that'll be fine we're going to create a small function in here uh we'll call it populate score row and we'll pass in some data here so what we'll do is we'll have a dollar sign id dot text is equal to str data we're going to grab from an array or from a dictionary id and then we're gonna do the same thing we duplicate that twice we're gonna grab name and we're gonna grab score and that conveniently matches exactly what we have here right we're trying to pull back this data so you can see this data here matches this data here and then we're going to need to change this to name and we're going to change this to score all right so what's going to happen is is whenever this gets substantiated we're going to call this function we're going to send it some data and it's going to populate these values with the data that it's expecting okay so what we're going to do is we'll go back to our tutor or our tutorial firebase example project and we will create a small function here called populate scoreboard and we'll pass in some data and then what we're going to do is we're going to say var scoreboard row template is equal to uh load res colon slash slash and we want to do score row dot tscn what that's going to allow us to do is it's going to allow us to populate our scoreboard with data so we'll say for i in data go ahead and do a var current score current score row is equal to scoreboard row template dot dot instance so the reason why we're assigning this to an object it's so that we can when we instantiate our um object we can go ahead and call some data from it so what we can do is we can say add underscore child below node and we can go dollar sign node 2d vbox container comma current oops current score row and what that will do is that will allow me to add when we instantiate a new score row it's going to add it right underneath here right but now we need to populate that score row with data so let's say current score row dot populate score row we're going to pass in the data here so if we go back to our score row gd script we have populate score row let's make sure that's exactly the same it should be but i'm hor i've been known to spell pretty poorly so awesome so now once we get back our firestore data let's go ahead and populate scoreboard and we'll have to go with our json data dot result and we're going to want to pass in our score i believe it's scoreboard right here so this little collection there you go so what we're doing is we're basically saying hey go out load that document worth of data come down here when you when you're done loading and populate that scoreboard with new data and then come down here instantiate a new version of this scene here loop through it i'm sorry grab this scene here loop through our data instantiate a row for each one of that of the data that we got back and add a child below this node 2d and then populate our score row makes sense right so now that we've got to this point what we can do is we can build this out and test it all right we're going to go ahead and click the little android button so go ahead and click that and it's going to go ahead and export it out to my machine or to my cell phone here and what we should see and i'm going to do a multiple tests here but what we should see is we should see a scoreboard pop up at least that that score information pop up there and we should have some of our data here and also i can show you the reward uh callback and i can show you the interstitial ad as well and that way i can kind of reinforce that all this stuff is really easy once you actually have it going it's it's quite simple to implement unfortunately this tutorial is extremely long so we do have it um loaded but you don't see any of my um scoreboard here and the reason why at least my guess as to the reason why and we're about to find out real quick we're going to do an adb logcat dash s godot to kind of get some more information here uh we have an invalid index on base in on base dictionary invalid index so it looks like it went out it fetched our data here so you can see it definitely fetched out our data see right here so that's good news we did get the data back but it looks like i got an invalid index id on base dictionary so we're going to have to take a look at that and see what's going on but first let's go ahead and click on our interstitial ad which should be this one and there we go it is now working and we can click our little reward at and it's gonna do it's gonna fire as he says the reward callback and you can see that our reward amount has changed which is great now you can see that we got like three or four of them here and the reason why is because we're not specifically looking for um our uh reward video status like watched we're actually just if i remember correctly here yeah we're just um grabbing it if the reward video throws a key so we could grab the data here and say hey if they watch it if it's a reward callback in this case when it loads when it shows then when it completes and then it when it uh loads again you get reward points so you would need to change this to only allow for that callback which if you look at here you can find out real easy let's see so you see here banner on add load reward video status loaded so you would want to change something in here to go ahead and adjust that let's go ahead and take a look at our script here id get data id let's do a print data let's go ahead and re-fire this off and let's see if anything special comes out of this so i'll be right back i see so the data that it passed in is fine point cgi id one name fine point cgi it looks like so we actually made a mistake because we just passed in our data here instead of passing in data i and that would be most likely the reason why so let's go ahead and reload this and let's take a look at it all right and there you go now it's a little on the funky side because for some reason and i'm wondering if that's something i'm doing wrong here but it did appear in the upper right hand corner which is good so at least it appeared and you can see that it does actually work it went out and it fetched the data from the firebase site and pulled it down so that's awesome right that's great it's it's at least working okay so the issue looks like it was just me needing to add child like this instead of adding child like the way i was before and as you guys can see it does work now so now we need to move on to the last one of our entire little project here and that is authentication now authentication is the hardest one to get done i'm not gonna lie and it's very likely that something's gonna break on me here so let's hope that it's easy and it goes well but we'll go from there so if you come back to godot firebase you scroll up to authentication here go ahead and get started and we are going to allow for google authentication and we're going to set our project support email and i already have this blurred out for you guys so you guys can't see it and we need our project public facing name so copy this data here you need this this is very important go ahead and hit save all right now we're gonna need to download our latest configuration file but first we need to configure our shot one certificate now if you guys already have your debug certificate set up which you guys should if you guys are doing this tutorial because we've been exporting this entire time so you definitely should have it what we need to do is we need to go out and get that shot fingerprint information and give it to authenticate with our authentication system so that it knows that we have a proper api key if that makes sense or a proper you know key to to authenticate with google servers so the first thing that we're going to need to do is we're going to need to reopen up visual studio code here we're going to need to change a setting inside of here which is out in our build.gradle let's see build.gradle here if you scroll down there should be a section called build types all so let's go ahead and look for that real quick actually i'm just going to control f build types all you can see right here there it is and it looks like it's going to be line 118 for you guys and go ahead and add res value space string comma server underscore client underscore id comma and then we need to paste in our project identifier so what that's going to do is it's going to tell the zipping and signing of your uh build information basically will have your project id in here so that way when your uh godot plug-in goes out and tries to pull the server client id information it has that information if that makes sense so now we need to come over here oh and actually before we go any further with this i almost forgot we need to be able to put data out to the firebase system i forgot about that so let's go ahead and create a quick button here so adding a child node so let's do that real quick that's my fault so let's put that right underneath reward we'll just say add score to database we're going to call this score 2db we're gonna attach a node to it as a button up we're gonna put that into our node here my apologies for that i've just completely spaced on that halfway halfway through here so we're gonna say var e entry is equal to open brace close brace and we're going to say dn which is another youtuber i don't know if you guys know that um open brace here we're going to say quote id poland is equal to one comma quote name colon is equal to dnn and score is equal to 253 what that's going to do is it's going to create entry for us here and we're going to want to pass that data in to our firebase prod our firebase so firebase dot buyer store underscore add underscore document quote i believe it's capital scoreboard yup right here so scoreboard and then comma my entry awesome so now if we build that out right off hand all right so now you can see this little add score to database so if we click this button here all right it's been clicked so let's go ahead and check our firebase and let me actually just reopen a tab here with this so that way i'm not losing what i was working on so let's open up our firebase test project and let's open up our firestore database and you can see there it is i've got a dean in id name score now you can see that it did add a document here so this isn't gonna work so let's go ahead and delete that field that's fine oh i think i have to yeah i have to do it up here so delete document let's go ahead and delete that and let's go back to our project and instead of having dean in here let's just have our entry as a native entry here awesome so that way next time when it pops this data in here it's going to throw it out onto the server and then when we reload this project it'll actually have his information in there which will be great so now that we got that done let's go back to authentication so if we come back to here you have this in here that's exactly what we want now we need to get our authentication fingerprint so we need to generate a shot one now you need to go out to wherever your your key store is located and your key store is like the way that you generate all of your or the way that you sign your project so in my case it's out into my username and then it's right here debug key store and you can name it you know you could have it be your release key store as well the commands are the exact same so what we're going to do is we'll go cmd and we will drag this to the center for you and we're gonna type key tool dash list space dash v space dash key store debug key store now if you have a release key store you just do release or you know whatever the name of your key star is you just do that name now it's going to ask you for a password if it's a debug keystore the password is android alright now we have our sha1 here you see this number right here that's your unique number remember it don't lose it save it you know well you don't have to save it you can just rerun this command but just know that that's your unique number so now somebody can go steal my my key store which isn't that big of a deal but i digress um if we go back to our firebase section here we need to go configure our certificate so if we go to our settings here we say project settings and we scroll down there is a sha certificate fingerprint section right here so we're going to go ahead and add a certificate fingerprint we're going to paste that in and save and what that's going to do is that's going to add that fingerprint to our project so now we can go ahead and authenticate with the google servers now first i'm going to want to go here grab this public facing name if you remember this public facing name we had this conversation earlier we need that so let's go ahead and copy that and we're going to need to download our google json file so it's right here just click that it's going to go ahead and download it i'm just going to click on this one yep that's fine i'm okay with with removing the one that we currently have and we're going to go out to our downloads folder we're going to copy this we are going to go to document good old tutorial android firebase so godot tutorial android firebase right here android build and we're going to re-paste in our google services.json now that we have all of that let's go into our visual studio code and let's type in our search server underscore client id all right let's see what we can see okay so we already added that here so we should in theory be good so let's go ahead and come in here and let's call out and and this is the only authentication i'm gonna have us do in this video if you guys want me to go more in depth with all of the other authentication options let me know and i'll be more than happy to dive right in and give you guys a good like here's how to do all of them but in this case i'm only going to show you google because the rest of them are honestly kind of a pain in the butt so we're going to right click add a child node we're going to add a button and we're going to say off with google alright and we're going to say off all right we're going to drag this down here right here and we're going to add in add any child node add in a node or i guess i should probably just grab a node 2d and we'll put this i don't know somewhere over here i guess here's good and we'll add in another child node and call it rich text label and we're going to put that underneath our node2d and we're just going to call this user info put this down here like this we'll say username and i'd rather not have a space if i can avoid it put this down below that and put email and we're gonna go and pull a texture and we'll put a texture right here so we're gonna go back to our little script here and we're going to attempt actually first we need to do our hookup so off with google node on button up let's hook it up here and we're gonna say firebase dot authentication underscore google underscore sign underscore in awesome now let's make sure that i spelled authentication correctly because again my spelling is horrible all right and now what we're gonna do is we are going to get our user information from here so var user underscore details and we're going to say that's equal to firebase authentication google right here we'll get this again get underscore user and then we need to parse that data that's going to come back so var parsed underscore json is equal to json.parse user underscore details and then var data is equal to parsed underscore json.result oops not add user signal awesome and then what we're going to do is if the data is equal to null then we just want to return because if we got an error we don't want it to blow up on us we'd like it to you know return and actually you know error out gracefully i guess would be the right words there so you'll notice that we had to click it twice before we could get our data back and the reason why is firebase authentication google sign-in is taking too long to come back with data so we actually need to take this data and let's pull that out of here and let's come up here to our little firebase section here and we'll say hey if from quote authentication make sure that i spelled that correctly whoops i forgot my little colon and if data then we're going to want to do this little bit of stuff here so let's take all this and put her up here and one of the beautiful things and i'm going to double check make sure that i spelled this correctly i did great one of the things that we need to be aware of is and the data's already yep so we'll say user data so let's copy this and refactor this a tiny bit whoops and refactored all right and if data user data whoops print our user data there we are all right and what this basically is gonna do is it's just gonna going to run after we get our callback so that way we know that it's done versus doing it the other way where we're we weren't fully sure so now what i can do is i can run this real quick and you'll see that it will come back with our data properly and everything will show up and everything will work great now one of the nice things about the google authentication is once you've authenticated with google once you don't have to do it again so you'll see that when i click off with google it's not even going to pop up it's just going to pull the data immediately and we're not going to have to deal with this anymore so that's one of the nice advantages of authenticating with google or with twitter or really with any of the authentication key systems that they have out there versus like user um user and password right so if i go ahead and i hit off with google bam it pulled all the data that we needed and that was it no problem so we have one final thing to take a look at and i know it's been a a very very long day uh it's been a very long tutorial okay so now we have one last thing and i know it's been a really long tutorial but we have one last thing to take a look at and then we'll be out of here and that is analytics so analytics is pretty simple if you go to the godot firebase page and you scroll down here there is a section called analytics so now if we go to events you'll see that we have some basic events already done for us and that is like somebody authenticated or somebody logged in or something like that right but what we also need to do is we need to pass and actually i think if we go to our dashboard we can actually see all of our analytics here right so we can see that we have a all sorts of crazy stuff all sorts of information here but what we can do is we can pass our data our analytic data back to the google analytics servers so if we tab back into our project here i'm just going to throw it in ready but you guys can go ahead and throw it wherever you'd like but we're going to do is we'll throw a firebase dot analytics underscore send underscore events and then we're going to give it an event name and we'll just call it test event comma and you can throw it a dictionary of data so let's say var crash right is equal to and we'll say you know crash data is equal to this app crashed and we can pass in our crash data or if we want to we can go firebase dot analytics underscore send underscore custom and that should allow us to send a event comma this is a test event and now if we go ahead and run this it should spit out our analytics data to our godot firebase here so let's see what happens all right so it's been about 24 hours it usually takes about 24 hours for you to see your google analytics pop up but here is what it looks like so you see here's our test event you can see that we've had one user send out that event you can actually click on it and give you a bit more information like hey how many users how many events how many counts per user how many events per session so how many times you know that application opens and it throws out that event and where that event came from cc i'm from the united states so it comes from the united states now you can also see with your analytics dashboard now that some time has gone by you can actually see how many active users you've had what users were engaged what they were doing you know were they looking at ad activity were they looking at things like that and you could finally take a look at how many apps if it did crash or didn't crash you can actually see if it crashed and you can see what your app at adoption rate is so you can actually see hey you know 100 percent people are on version 1.0 you can see where people are from and what platforms they're on so google analytics is really useful for just keeping track of all of your stuff and and making sure that your app is running the way that you would expect it to all right so that's what i have for you guys today so we went over what firebase is how to integrate it with android godot we went through the process of adding cloud messaging and subscribing to a topic we loaded in our documents and set up a firestore database and hooked all that up we went through and added admob to our project and added reward videos and interstitial um advertisements and and banner advertisements and we went through the process of setting up authentication with google so we could get back user data for our project so that's really all i have for you guys so if you like this video hit that like button if you dislike this video hit that dislike button because i'm here to make content for you guys now this video was also a a viewer request and i get all my ideas from you guys so go ahead and shoot them in the comments below and let me know what kind of video you got let me know what kind of videos you guys want and i'll be more than happy to add them to my list i mean my list is ever growing but i'm always happy to add it to my list and make sure that it happens so thank you guys so much for watching i'll see you all next time thanks [Music] you
Info
Channel: FinePointCGI
Views: 1,663
Rating: undefined out of 5
Keywords: godot, godot firebase, godot android, firebase, godot tutorial, android, godot firebase tutorial, godot engine, godot firebase plugin, firebase tutorial, firebase android tutorial, godot game engine, godot review, firebase database android, android studio tutorial, firebase database android app, godot engine firebase, godot google firebase, godot for android, godot android ads, godot engine tutorial, godot beginner tutorial, what is godot, godot explained, godot online, admob
Id: -ybnJ8CXScQ
Channel Id: undefined
Length: 75min 12sec (4512 seconds)
Published: Mon Apr 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.