question

Joshua McGrath avatar image
Joshua McGrath asked

GameCircle: Unity Crashing after Init - A solution.

Hello Everybody. I spend a day or so wrangling with GameCircle and have come back from the desert to give you a solution to your potential Unity crashing woes. Minor trivia first: 1) Be sure your AndroidManifest.xml contains: Major trivia now: You will need to modify the following files: AGSProfilesClient AGSLeaderboardsClient AGSAchievementsClient They currently use a static constructor in which your JavaObject is initialized. We want to rename this to be a normal function (called, say: public static void Initialize()). We are going to assure that it is being called at the correct time. The functions will now look like: AGSProfilesClient.Initialize(); AGSLeaderboardsClient.Initialize(); AGSAchievementsClient.Initialize(); These classes inherit from Monobehavior. I added these to an object each in the hierarchy - named the same as the class. I do not know if this is mandatory - but it is a delicate ecosystem. Your workflow will should like this: 1) Application launches 2) Call AGSClient.Init and wait on your ServiceReadyHandler 3) When the ServiceReadyHandler returns positively: 4) Call AGSProfilesClient.Initialize(); 5) Call AGSLeaderboardsClient.Initialize(); 6) Call AGSAchievementsClient.Initialize(); 7) Register listeners for PlayerAliasReceivedEvent / PlayerAliasFailedEvent in AGSProfilesClient if you need to 8) At this point - you can now launch into your usual application logic. Open leaderboards, submit scores, update achievements. The critical timing here is: 1) Initialize 2) Wait for Service to be ready 3) When service is ready, initialize the three core classes above 4) Now that these are initialized, make whatever requests you like. I hope this is helpful to those of you wrangling with Unity issues! -JFFM [i][/i][i][/i]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Thanks Jffm_di. This will help the unity developers a lot.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kamikaze139 avatar image
kamikaze139 answered
Hey, Thanks for the solution. It solved our problems too. You made my day :) One additional note: The classes [i]AGSAchievementsClient[/i], [i]AGSLeaderboardsClient[/i] and [i]AGSProfilesClient[/i] do not need to be attached to any object inside the scene. Also, they don't even need to inherit from [i]MonoBehaviour[/i], as they only consist of static functions. Removing the inheritance and the constructors and calling a static initialize function after the service ready was returned successfully worked fine for me.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

steve-thorne avatar image
steve-thorne answered
Thanks so much for this solution! Works great
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

LionTR avatar image
LionTR answered
One more thanks from here as well!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
Also, in AGSWhispersyncClient there is a case sensitivity issue with javaObject and JavaObject... Thanks for this thread!
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
That said, nothing here seems to be working. AGSClient crashes at this point: using( var PluginClass = new AndroidJavaClass( PROXY_CLASS_NAME ) ){ Stating that this is a null ptr: private static readonly string PROXY_CLASS_NAME = "com.amazon.ags.api.unity.AmazonGamesClientProxyImpl"; The code: //Tried in Awake and Start Callback, both fail Start just takes longer to do so #if UNITY_ANDROID if( CrossPlatform.build == "Amazon" ) { AGSClient.ServiceReadyEvent += serviceReadyHandler; AGSClient.ServiceNotReadyEvent += serviceNotReadyHandler; AGSClient.Init(); //Dies here } #endif function serviceNotReadyHandler( error : String ) { Debug.Log("Service is not ready"); CrossIAP.RequestProductData(); } function serviceReadyHandler() { CrossIAP.RequestProductData(); AGSAchievementsClient.Initialize(); AGSLeaderboardsClient.Initialize(); AGSProfilesClient.Initialize(); AGSWhispersyncClient.Initialize(); }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
If the same logic as the other classes is followed for AGSClient... if( CrossPlatform.build == "Amazon" ) { AGSClient.ServiceReadyEvent += serviceReadyHandler; AGSClient.ServiceNotReadyEvent += serviceNotReadyHandler; AGSClient.Initialize(); //Dies here after turning static constructor into public static void Initialize() //AGSClient.Init(); }
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
Actually, that's a negative. It doesn't crash until AGSClient.Init() ...
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
OK, tracked it down. There were two api_key.txt files in the project (one was included by a Prime31 plugin). I added one where Amazon's instructions stated but the Prime31 version was getting read. I simply filled in both and it worked.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jeremy Alessi avatar image
Jeremy Alessi answered
Sweet, GameCircle works but just when the banner appears it cuts the game's audio...
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.