godot-sdk-integrations / godot-play-game-services

A Godot 4.x plugin for integration with Google Play Game Services
MIT License
138 stars 10 forks source link

What changes are required for 4.3? #32

Closed TheSkyOne closed 2 weeks ago

TheSkyOne commented 1 month ago

Hello! I have updated to Godot 4.3, and the plugin stopped logging-in on app launch. I am getting "Plugin found" printed from godot_play_game_services.gd so that's not the issue. I tried pasting this code from the demo project

func _ready() -> void:
    SignInClient.user_authenticated.connect(func(is_authenticated: bool):
        if not is_authenticated:
            SignInClient.sign_in()
    )

to try to force it to sign in, and I did get the sign-in prompt, but even when I pressed "continue" it would keep prompting me again and again. and also never signing me in successfully (when I closed and opened the app again things I save weren't saved, this used to work when I was in Godot 4.2) help updating to Godot 4.3 would be much appreciated!

Iakobs commented 1 month ago

Hi @TheSkyOne thanks a lot for letting me know! I haven't tried the plugin yet in godot 4.3, my bad! I'm out for the weekend but as soon as I get back to my computer I'll check the issue! Thanks for your patience!

Iakobs commented 1 month ago

Hi @TheSkyOne I've updated the plugin for Godot 4.3 and launched a new release. Can you try it out now and see if this fixes your issue? It definitely worked for me, but you know, it's better to check!

TheSkyOne commented 1 month ago

Thank you for updating so quickly! I was just about to make an update, for some odd reason when I released a new update to my app and downloaded it on my device, and the signing-in and saving worked. but when launching with remote debug to my device from the godot editor it doesnt work, but it used to. I am not sure if I should update or not. does it sign in to your account for you when you launch with remote debug from the editor?

Iakobs commented 1 month ago

Yes, I tested it launching from the godot editor with WiFi debugging and it worked fine. You can give a try and update the plugin to see if it works

TheSkyOne commented 1 month ago

OK, I will update you

TheSkyOne commented 1 month ago

By the way, I have made some minor local changes to the plugin, is there a way for me to not override those changes when updating to the new version? sorry bit of a newbie to this 😅

Iakobs commented 1 month ago

I don't think your changes overlap mine, so you can move your changes to a separate place temporarily, download the new version of the plugin and then copy and overwrite your changes on top, that should be safe and you won't lost your changes

TheSkyOne commented 1 month ago

I still cant get it to show the sign-in at the top on remote debugging

TheSkyOne commented 1 month ago

also note about something small, I noticed the version in the config file hasnt changed

Iakobs commented 1 month ago

also note about something small, I noticed the version in the config file hasnt changed

You mean the plugin version from 1.7.0 to 1.8.0? I forgot about that, thanks for pointing out! But that doesn't affect anything.

I have an idea, but I'm not sure that would help, can you try deleting the android/build folder of your Godot project and reinstalling the android template from the godot editor?

TheSkyOne commented 1 month ago

yeah ik the version doesnt affect it, just wanted to keep it up to date 😄 I will try reinstalling the build template

TheSkyOne commented 1 month ago

no change

Iakobs commented 1 month ago

I'm sorry to hear that but I'm afraid I can't help much more without looking at the code. I imagine you've followed the implementation guide, right? https://github.com/Iakobs/godot-play-game-services/blob/main/plugin/demo/README.adoc

TheSkyOne commented 1 month ago

I will try to do a full restart and follow all the steps again, will update tomorrow if it worked

Iakobs commented 1 month ago

Hi @TheSkyOne did you manage to solve your issue?

TheSkyOne commented 1 month ago

Hey! my computer has been having some issues the past few days so I havent been able to test yet. Hopefully I will be able to soon, and I will update here whether or not I have managed to solve it. thank you for following up! :)

Iakobs commented 1 month ago

Hi @TheSkyOne how is it going? Let me know if you need something else 😊

TheSkyOne commented 1 month ago

Hi @Iakobs unfortunately it is going to be a little while before i can test. i really appreciate you taking the time you follow up, and i will write here once i get on it, it might just be a while before i can. thanks again 🙂

Iakobs commented 1 month ago

Sure no problem! :)

TheSkyOne commented 3 weeks ago

@Iakobs so i finally was able to get back to this, i deleted everything related to the plugin and started from scratch. i am now at the same place i was when i open this issue, that is, im getting the sign-in popup as seen here Screenshot_20241001-155839 but regardless of pressing "continue" or "cancel" the popup closes and immediately reopens, creating a loop where i cant do anything. this is the sign-in code (straight from the demo)

SignInClient.user_authenticated.connect(
    func(is_authenticated: bool):
    if not is_authenticated:
        SignInClient.sign_in()
    )

this is running on my first scene that gets loaded on game start (splash screen). interestingly, i noticed that if i put this same code in my main menu scene, which comes a little bit after, i dont get this sign-in popup at all. which i am guessing means is_authenticated is coming as true. meaning something else is attempting and successfully authenticates. does the plugin try to automatically authenticate when its loaded? if so, could that be causing some issue where the code above (which as i said gets run in the first scene in the game) is racing against the plugin and that somehow causes the weird cycle? im really just taking shots in the dark here tbh...

Iakobs commented 3 weeks ago

Hi! Yes, as mentioned here, the plugin attempts to login when loaded. The Google workflow for logging in is a bit strange, so it makes sense that the code you posted from my example might enter in a loop. In the demo project there's a retry mechanism with a finite number of retries if you want to implement something similar.

I understand that the plugin is working, it's just a matter of implementing the workflow, right? Let me know if I can help you with something else.

TheSkyOne commented 3 weeks ago

i guess the issue is, why is there even a retry when i press "continue" or "cancel" on the prompt. like i would expect it to just either load the user or not load it depending on my choice, not prompt me again if that makes sense. is there a way to prevent it from doing that? also could you please direct me to where exactly in the demo it checks for a maximum number of attempts?

Iakobs commented 2 weeks ago

I see, yes, that behaviour is very weird. That sign in window is provided by Google and it's not configurable. I don't see any option in their documentation to modify its behaviour.

The part in the demo where I do the retry mechanism is in this gdscript file.

TheSkyOne commented 2 weeks ago

so this feels like a bandaid fix, but it does work to stop it from repeating trying to sign in var sign_in_attempts = 1 and

func _sign_in() -> void:
    SignInClient.user_authenticated.connect(
        func(is_authenticated: bool):
        if sign_in_attempts > 0 and not is_authenticated:
            SignInClient.sign_in()
            sign_in_attempts -= 1
    )

which i call in ready. currently, i am struggling with getting things to save. i am trying to run your demo project but when i remote debug it it fails to export with this error

* What went wrong:
  Execution failed for task ':processDebugResources'.
  > A failure occurred while executing com.android.build.gradle.internal.res.LinkApplicationAndroidResourcesTask$TaskAction
     > Android resource linking failed
       ERROR: C:\Users\USER\Downloads\Iakobs godot-play-game-services main plugin-demo\android\build\src\debug\AndroidManifest.xml:23:1-113: AAPT: error: resource string/game_services_project_id (aka com.example.googleplaygameservicesgodotplugin:string/game_services_project_id) not found.

which makes sense because i dont have the game services project id for this, but then im not sure how im supposed to test things. unless the demo project is just meant as a code example and not meant to be ran. in any case, i dont think there is an actual issue with the plug-in, its just me probably misunderstanding and using it wrong (even tho i had it working at some point earlier). so i guess this issue can be closed?

Iakobs commented 2 weeks ago

Hi, sorry for the delay!

The demo project does work, but you have to provide a project Id to it via the new tab in the dock. I haven't tested with other ids beside mine, but in theory it should work with any id.

You can close the issue if you want. I can try to help you with the saving games part too, what's the issue you're facing?

TheSkyOne commented 2 weeks ago

after more debugging, i seem to be having issues signing-in at all, rather than saving issues. currently i have this code in my main menu scene

SignInClient.user_authenticated.connect(
    func(is_authenticated: bool): 
        print("user authenticated: " + str(is_authenticated))
           )
SignInClient.sign_in()
await SignInClient.user_authenticated
SignInClient.is_authenticated()

which results in this output

user authenticated: false
user authenticated: false

when i press the "continue" button on the prompt i shared a few messages above (by the way, i keep getting that prompt, instead of just seeing the game automatically connect with a popup from the top like it usually does in games, and im not sure why that is) also, i tried putting my game's play games ID in your demo and it does work, but it behaves the same as my own game, it keeps prompting me to sign in, until i eventually get attempts expired. another thing i dont understand, is how your code in the main menu initiates the sign-in process.

SignInClient.user_authenticated.connect(func(is_authenticated: bool):
    if _sign_in_retries > 0 and not is_authenticated:
        title_label.text = "Trying to sign in!"
        SignInClient.sign_in()
        _sign_in_retries -= 1

this only connects the user_authenticated signal to the lambda function, according to your docs this signal is emitted by is_authenticated() and sign_in(). for the former i couldnt find any call within the project, and the latter is only called within the same lambda function... i am asking this because i have pretty much the same code, which you can see in my comment above, but mine doesnt get initiated unless i call the functions from the SignInClient manually... your help is much appreciated! 🙏

Iakobs commented 2 weeks ago

Oh I see. That's maybe not clear in the docs and I'll try to explain it better. I never call the is_authenticated method in the demo app, because it's called internally when the plugin is loaded, that's why I only connect to the signal and, in case the user is not authenticated, I attempt the other method.

Maybe you can try without sign in code at all, and see if the automatic attempt works by its own?

About the prompt, that's weird. I never had it while testing, I either couldn't sign in or I was automatically signed in. Maybe also important to note that I'm logged in the Google Play Games app before opening the demo app. That's something else you can try it you haven't.

TheSkyOne commented 2 weeks ago

i tried with no sign in code at all, simply nothing happens, is it possible that somehow the plugin is not attempting to sign in implicitly for me? i am connected to the internet and the app as correct permissions. about the prompt, i am signed-in in the google play games app too. something i tried was to download my app from the link in my google play console. that gives me an older build of the app which i uploaded to internal testing in the console. when i run that build i get signed-in as you would expect. i then uninstall that version from my device (because if you dont you get an error about a version mismatch) and then used remote debugging to install my current app build (which is not uploaded to the console) and for some reason that also signs-in as you would expect... but i found that it stops working after a little while, so this is clearly not a solution or anything, just sharing more information hoping it helps... this is very confusing.

Iakobs commented 2 weeks ago

Wow, that's indeed very confusing of an issue. What do the logs say? Maybe it's a problem with the credentials in the Google cloud? It sounds like maybe there's a cache for it and that's why your build works some time after running the one in the console.

TheSkyOne commented 2 weeks ago

what logs are you referring to particularly?

Iakobs commented 2 weeks ago

the app logs, in logcat. If you filter by package:com.google.android.gms you should see only the google games related logs.

TheSkyOne commented 2 weeks ago

that was a good shout by you! it seems like my game's SHA-1 certificate changed somehow? in the logs in is showing a sequence i recognize, but going to the google console, both "App signing key certificate" and "Upload key certificate" are different than that key... im not sure what would cause the key to change tho, and would like to avoid this happening again...

Iakobs commented 2 weeks ago

Nice! This happened to me too, that's why I put this section in the README.

TheSkyOne commented 2 weeks ago

yeah, i went through it just after discovering the issue in the logs. so do i need to delete the existing credentials and recreate them with the new sha-1 certificate?

Iakobs commented 2 weeks ago

I don't think you have to delete them, iirc you can just edit them. But if you feel safer deleting them, that's OK too!

TheSkyOne commented 2 weeks ago

oh ok it is possible to just edit them? i am asking because i am not in charge of the google cloud account for the project so i need to relay instructions accurately as to how fix this so i can keep development. i will try that and will update once i can (hopefully) confirm everything works. thanks a bunch so far!

Iakobs commented 2 weeks ago

Yes, that needs to be changed in the Oauth client in the Google Cloud. The basic steps are described here, and the changes are made here:

image

Just click in any of the credentials that are already created and there you can edit the package name and the SHA1. Basically you need an oauth client for every keystore you are using. Say if your team has 3 memeber who develop in their machines, that will be AT LEAST 3 different oauth clients with the SHA1 that every dev must provide running this command over their keystore: keytool -keystore path-to-debug-or-production-keystore -list -v. I usually have 2 different keystores in my own machine, one for debug mode of the game and the other for release mode of the game.

Then you need another oauth with the SHA1 of the play store for the game to run when downloaded from the store. That SHA1 is controlled by Google, but available in the Play Console.

Then, for every oauth client in Google Cloud, there needs to be a matching credential in the Game Services section of the Game in the play console, here:

image

And finally, always remember to publish any changes related to play games services, that's a different publish workflow than the whole game.

Hope it makes sense!

TheSkyOne commented 2 weeks ago

updating, after updating the wrong sha-1 cert (still no idea what made it change) to the correct one i can now sign in as usual! hopefully saving will be easy to do now as i have already done it before. thanks a lot for all your help and the maintenance of this plugin 🙇

Iakobs commented 2 weeks ago

no worries at all! I'll close the issue for now, but feel free to open a new one if you need help with snapshots!