Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Custom Behaviours in Offline Mode

Discussion in 'Unity IAP' started by Raghavendra, Nov 24, 2020.

Thread Status:
Not open for further replies.
  1. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Hi,

    I need the following custom behaviours on offline mode. So it would be great if someone can guide me.

    1) Need to show custom "No Internet" popup when the user taps on any IAP buttons. Currently, the IAP buttons get disabled in offline mode. So, is there any way to prevent this?

    2) Need the IAP buttons to work if the user goes from offline to online in the store. Currently, i need to come out of the store and go back for it to work. (I guess this should get solved along-with point 1).

    Note: I am using GameFoundation in my game. And i had posted this on GameFoundation sub-forum but i was advised to open the topic here as it is Unity IAP related.

    Thank you
     
  2. John_Corbett

    John_Corbett

    Unity Technologies

    Joined:
    May 17, 2019
    Posts:
    151
    Hi Raghavendra,

    Are you using the IAP button class from the Window | Unity IAP | IAP Button menu?

    If that's the case, just to be sure, have you added a function to show your "No Internet" popup to the OnClick of the Button component? The button component itself should not be being enabled or disabled, but if that's the case we'll investigate.
     
  3. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    I am using Game Foundation and have used the PurchaseButton component that comes with it.
     
  4. John_Corbett

    John_Corbett

    Unity Technologies

    Joined:
    May 17, 2019
    Posts:
    151
    Ah!

    Can you please direct your question to the Game Foundation forums here: https://forum.unity.com/forums/game-foundation.416/

    Unfortunately I am not an expert on Game Foundation, but our team over there will be glad to help you. If they need my advice on IAP-Game Foundation interactions, I will help them.
     
  5. tony_c-unity3d

    tony_c-unity3d

    Unity Technologies

    Joined:
    Jul 18, 2019
    Posts:
    35
    @Raghavendra ,

    Sorry for the confusion, but we're having a bit of trouble tracking down your issue. I rebuilt our samples project "01_Store/Grid Store - Landscape" today, started the game offline as well as going offline while already playing and never witnessed the buy button being disabled. In my test, the request was passed down to IAP where it failed (as expected--you can't purchase offline).

    If you wanted to send us your test app, we could try to dig into the issue further. Please note that most of our team is US-based so there will be some availability issues due to the holidays, but we'd like to know more about what you're experiencing so we can try to assist you as much as possible.

    Another option you might consider is rewiring the 'buy' button so you can have a custom script intercept the offline response and handle it yourself. Again, not sure how your app is setup, but there may be an opportunity for some custom code there.

    I'll go ahead and try 1-2 other store sample projects to try to reproduce the change you're seeing in the buy button.

    I'll also pass along your question to our PM to see if he has any thoughts or if this is something we could work into a future release.

    Thanks again for reaching out and good luck!
     
  6. tony_c-unity3d

    tony_c-unity3d

    Unity Technologies

    Joined:
    Jul 18, 2019
    Posts:
    35
    @Raghavendra ,

    Just wanted to follow up to see if you might want to send us a test project so we can help you debug the issue you're experiencing. I did try other samples on device while changing online status at various times and was never witnessed any change in our buy button--it was always interactable, and, if clicked while offline, a message appeared that you couldn't purchase so it seemed to work as expected, at least in our sample projects.

    Again, best of luck; please let us know if we can help further.
     
    Raghavendra likes this.
  7. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Thanks for the follow up. Sending the test project won't be possible as it's a huge project, and I do have a lot of custom scripts for handling lots of custom behaviours. Let me try the sample projects myself and see what happens on my side. Thanks once again.
     
  8. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    The buttons get disabled only if i start the game in offline mode i.e if the IAPs don't initialize. Is it okay if i initialize them manually in offline mode? Otherwise if i start the game in online mode and then toggle the status, then yes, the buttons are enabled and i get the native message. So, regarding this. Is there any way to prevent the native popup? I want to show a custom no-internet connection popup instead.
     
  9. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    One more thing to add. The buttons get disabled if i start offline but they do get enabled again if i connect to internet. But i want the buttons to be enabled even in offline mode.
     
  10. tony_c-unity3d

    tony_c-unity3d

    Unity Technologies

    Joined:
    Jul 18, 2019
    Posts:
    35
    @Raghavendra, Strange, I wasn't getting that behavior when I tested on android with the sample scenes. That might be a good place to start--would you mind using the Game Foundation Prefabs Sample "01_Store" scene "Grid Store - Landscape" to test if you can replicate your issue? Also, please let us know if you testing on android or any other unique data about your test case to help us narrow down the problem you're experiencing.

    As far as the native popup you're receiving, I don't believe it's possible to avoid that once the request has been sent on to IAP--the best way to get the behavior you're looking for would be to catch the button press yourself and check online status before sending the request on to IAP for processing. Then you could handle it as you prefer when offline, and simply pass on for processing if player is online.

    @richj_unity has more experience with iap and is back from vacation today--would you mind weighing in on this? Do you have any other insights here that might be helpful?
     
  11. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Thanks for the reply. Yeah, I am currently testing it on Android. I'll try out your suggestions and get back.
     
    tony_c-unity3d likes this.
  12. tony_c-unity3d

    tony_c-unity3d

    Unity Technologies

    Joined:
    Jul 18, 2019
    Posts:
    35
    One thing I didn't mention is that you'll have to add an IAP product to the sample catalog to test (thanks @richj_unity for the offline reminder!). The sample scene only demonstrates virtual transactions, but, by adding 1 or more IAP products as well, you can use it to test button behaviors and IAP transactions using the prebuilt sample scene. Just a heads up, in case you run into trouble. Good luck and please reach out with your results or any other questions or problems you might have.
     
  13. Raghavendra

    Raghavendra

    Joined:
    Mar 14, 2014
    Posts:
    52
    Hi, got what i wanted by catching the button press separately like you suggested. Thanks.
     
    erika_d likes this.
Thread Status:
Not open for further replies.