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

IAP Looses callbacks when reload scene

Discussion in 'Editor & General Support' started by LimeJuice, Apr 25, 2018.

  1. LimeJuice

    LimeJuice

    Joined:
    Nov 8, 2012
    Posts:
    58
    Hello,
    I worked on a script using IStoreListener for In-App-Purchase based on this example:
    https://unity3d.com/learn/tutorials/topics/ads-analytics/integrating-unity-iap-your-game

    It all works fine until I reload the scene, after that, the script does not receive any callBacks.
    After looking online, I found 3 potential solutions:

    1. Use DontDestroyOnLoad in awake()
    https://forum.unity.com/threads/solved-unity-iap-initialization-issue.390407/
    Unfortunately, it does not work on my project, there is still no callBacks

    2. Add an exception in the app’s hierarchy cleanup script for the “IAPUtil” GameObject.
    https://support.unity3d.com/hc/en-u...llbacks-on-our-IStoreListener-implementation-

    Anyone knows how to do that?

    3. Use a singleton
    https://forum.unity.com/threads/solved-unity-iap-initialization-issue.390407/

    How do I use singleton and how does that impact my project?
    I understand that the class instance will leave after the scene is destroyed, what does that mean for the scene gameobjects linked in the class?
     
  2. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    You should be able to attach the script to an (empty) Gameobject that does not get unloaded, as described in the singleton post above. I believe DontDestroyOnLoad needs to be a root object, but I would need to confirm.
     
  3. LimeJuice

    LimeJuice

    Joined:
    Nov 8, 2012
    Posts:
    58
    Thanks, I did make it a singleton. Now I have a new issue. When I first lead the scene on iOS, I tap the buy button, the ios native purchase prompt pop up appears normally. But if I reload the scene, tap the button, a first pop up prompt appears and if I close it( buy pressing cancel or purchasing), a second pop up appears. If a reload again, it will be 3 pop ups ect...

    It's like if there was multiple version of my script running.
    But I am using DontDestroyOnLoad(gameObject) and Destroy (gameObject) to make sure there is only one script:

    public static Shop the_shop_instance;
    public void Awake() {

    // SINGLETON
    if (the_shop_instance == null) {

    //if not, set instance to this
    the_shop_instance = this;
    }
    //If instance already exists and it's not this:
    else if (the_shop_instance != this){

    //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
    Destroy (gameObject);
    }
    //Sets this to not be destroyed when reloading scene
    DontDestroyOnLoad(gameObject);
     
    Last edited: Jun 6, 2018
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
  5. LimeJuice

    LimeJuice

    Joined:
    Nov 8, 2012
    Posts:
    58
    Hi,
    for the pop up, I meant the native dialogue box that say: 'confirm your In-App Purchase, Do you want to buy one product for £0.99' with Cancel and Buy buttons.

    Here the log after reloading the scene once, the dialogue box appears twice and twice I pressed 'Cancel'

    Code (CSharp):
    1.  Purchace ios.sp_evil.id
    2. Shop:Purchase(Int32)
    3. OnPressBuyWCash:Invoke(Int32)
    4. shop_item:PressBuyWCash()
    5. UnityEngine.Events.UnityEvent:Invoke()
    6. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    7. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    8. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    9. UnityEngine.EventSystems.StandaloneInputModule:Process()
    10. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    11.  
    12. Show AllCoroutinesKilled
    13. LoadingPanelManager:ShowPanel(Boolean)
    14. Shop:Purchase(String)
    15. Shop:Purchase(Int32)
    16. OnPressBuyWCash:Invoke(Int32)
    17. shop_item:PressBuyWCash()
    18. UnityEngine.Events.UnityEvent:Invoke()
    19. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    20. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    21. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    22. UnityEngine.EventSystems.StandaloneInputModule:Process()
    23. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    24.  
    25. Shop EventOnStartProcess()
    26. Shop:Purchase(String)
    27. Shop:Purchase(Int32)
    28. OnPressBuyWCash:Invoke(Int32)
    29. shop_item:PressBuyWCash()
    30. UnityEngine.Events.UnityEvent:Invoke()
    31. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    32. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    33. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    34. UnityEngine.EventSystems.StandaloneInputModule:Process()
    35. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    36.  
    37. Purchasing product asychronously: 'ios.sp_evil.id'
    38. Shop:BuyProductID(String)
    39. Shop:Purchase(String)
    40. Shop:Purchase(Int32)
    41. OnPressBuyWCash:Invoke(Int32)
    42. shop_item:PressBuyWCash()
    43. UnityEngine.Events.UnityEvent:Invoke()
    44. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    45. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    46. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    47. UnityEngine.EventSystems.StandaloneInputModule:Process()
    48. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    49.  
    50. 2018-06-07 16:16:37.152754+0100 crunch[8818:4200638] UnityIAP: PurchaseProduct: ios.sp_evil.id
    51. 2018-06-07 16:16:37.157084+0100 crunch[8818:4200638] UnityIAP: UpdatedTransactions
    52. purchase({0}): ios.sp_evil.id
    53. Shop:Purchase(String)
    54. Shop:Purchase(Int32)
    55. OnPressBuyWCash:Invoke(Int32)
    56. shop_item:PressBuyWCash()
    57. UnityEngine.Events.UnityEvent:Invoke()
    58. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    59. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    60. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    61. UnityEngine.EventSystems.StandaloneInputModule:Process()
    62. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    63.  
    64. ios.sp_evil.id
    65. Shop:Purchase(Int32)
    66. OnPressBuyWCash:Invoke(Int32)
    67. shop_item:PressBuyWCash()
    68. UnityEngine.Events.UnityEvent:Invoke()
    69. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    70. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    71. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    72. UnityEngine.EventSystems.StandaloneInputModule:Process()
    73. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    74.  
    75. Purchace ios.sp_evil.id
    76. Shop:Purchase(Int32)
    77. shop_item:PressBuyWCash()
    78. UnityEngine.Events.UnityEvent:Invoke()
    79. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    80. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    81. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    82. UnityEngine.EventSystems.StandaloneInputModule:Process()
    83. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    84.  
    85. Show AllCoroutinesKilled
    86. LoadingPanelManager:ShowPanel(Boolean)
    87. Shop:Purchase(String)
    88. Shop:Purchase(Int32)
    89. shop_item:PressBuyWCash()
    90. UnityEngine.Events.UnityEvent:Invoke()
    91. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    92. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    93. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    94. UnityEngine.EventSystems.StandaloneInputModule:Process()
    95. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    96.  
    97. Shop EventOnStartProcess()
    98. Shop:Purchase(String)
    99. Shop:Purchase(Int32)
    100. shop_item:PressBuyWCash()
    101. UnityEngine.Events.UnityEvent:Invoke()
    102. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    103. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    104. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    105. UnityEngine.EventSystems.StandaloneInputModule:Process()
    106. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    107.  
    108. Purchasing product asychronously: 'ios.sp_evil.id'
    109. Shop:BuyProductID(String)
    110. Shop:Purchase(String)
    111. Shop:Purchase(Int32)
    112. shop_item:PressBuyWCash()
    113. UnityEngine.Events.UnityEvent:Invoke()
    114. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    115. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    116. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    117. UnityEngine.EventSystems.StandaloneInputModule:Process()
    118. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    119.  
    120. 2018-06-07 16:16:37.165753+0100 crunch[8818:4200638] UnityIAP: PurchaseProduct: ios.sp_evil.id
    121. 2018-06-07 16:16:37.166046+0100 crunch[8818:4200904] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    122. 2018-06-07 16:16:37.165014+0100 crunch[8818:4200903] You are usin2018-06-07 16:16:37.169555+0100 crunch[8818:4200638] UnityIAP: UpdatedTransactions
    123. purchase({0}): ios.sp_evil.id
    124. Shop:Purchase(String)
    125. Shop:Purchase(Int32)
    126. shop_item:PressBuyWCash()
    127. UnityEngine.Events.UnityEvent:Invoke()
    128. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    129. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    130. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    131. UnityEngine.EventSystems.StandaloneInputModule:Process()
    132. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    133.  
    134. ios.sp_evil.id
    135. Shop:Purchase(Int32)
    136. shop_item:PressBuyWCash()
    137. UnityEngine.Events.UnityEvent:Invoke()
    138. UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
    139. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchPress(PointerEventData, Boolean, Boolean)
    140. UnityEngine.EventSystems.StandaloneInputModule:ProcessTouchEvents()
    141. UnityEngine.EventSystems.StandaloneInputModule:Process()
    142. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    143.  
    144. 2018-06-07 16:16:37.184079+0100 crunch[8818:4200904] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    145. 2018-06-07 16:16:37.195942+0100 crunch[8818:4200904] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    146. 2018-06-07 16:16:37.202924+0100 crunch[8818:4200904] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    147. g download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    148. -> applicationWillResignActive()
    149. 2018-06-07 16:16:38.236132+0100 crunch[8818:4200905] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    150. 2018-06-07 16:16:38.238578+0100 crunch[8818:4200906] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    151. 2018-06-07 16:16:40.420308+0100 crunch[8818:4200638] UnityIAP: UpdatedTransactions
    152. 2018-06-07 16:16:40.420671+0100 crunch[8818:4200638] UnityIAP: PurchaseFailed: 2
    153. -> applicationDidBecomeActive()
    154. 2018-06-07 16:16:40.479342+0100 crunch[8818:4200913] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    155. onPurchaseFailedEvent({0}): ios.sp_evil.id
    156. UnityEngine.Purchasing.PurchasingManager:OnPurchaseFailed(PurchaseFailureDescription)
    157. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    158. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    159. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    160.  
    161. OnPurchaseFailed: FAIL. Product: 'ios.sp_evil.id', PurchaseFailureReason: UserCancelled
    162. Shop:OnPurchaseFailed(Product, PurchaseFailureReason)
    163. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    164. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    165. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    166.  
    167. Show AllCoroutinesKilled
    168. LoadingPanelManager:ShowPanel(Boolean)
    169. LoadingPanelManager:HidePanel()
    170. Shop:OnPurchaseFailed(Product, PurchaseFailureReason)
    171. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    172. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    173. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    174.  
    175. [Crashlytics] Recording exception: FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    176. Fabric.Internal.Crashlytics.CrashlyticsInit:HandleLog(String, String, LogType)
    177. UnityEngine.LogCallback:Invoke(String, String, LogType)
    178. UnityEngine.Application:CallLogCallback(String, String, LogType, Boolean)
    179. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    180.  
    181. [Crashlytics] Exception stack trace: System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args)
    182. System.String.Format (IFormatProvider provider, System.String format, System.Object[] args)
    183. Shop.OnPurchaseFailed (UnityEngine.Purchasing.Product product, PurchaseFailureReason failureReason)
    184. UnityEngine.Purchasing.JSONStore.OnPurchaseFailed (UnityEngine.Purchasing.Extension.PurchaseFailureDescription failure, System.String json)
    185. UnityEngine.Purchasing.Extension.UnityUtil.Update ()
    186.  
    187.  
    188. Fabric.Internal.Crashlytics.CrashlyticsInit:HandleLog(String, String, LogType)
    189. UnityEngine.LogCallback:Invoke(String, String, LogType)
    190. UnityEngine.Application:CallLogCallback(String, String, LogType, Boolean)
    191. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    192.  
    193. FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    194.   at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0
    195.   at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0
    196.   at Shop.OnPurchaseFailed (UnityEngine.Purchasing.Product product, PurchaseFailureReason failureReason) [0x00000] in <filename unknown>:0
    197.   at UnityEngine.Purchasing.JSONStore.OnPurchaseFailed (UnityEngine.Purchasing.Extension.PurchaseFailureDescription failure, System.String json) [0x00000] in <filename unknown>:0
    198.   at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <filename unknown>:0
    199. (Filename: currently not available on il2cpp Line: -1)
    200.  
    201. 2018-06-07 16:16:40.521812+0100 crunch[8818:4200908] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    202. 2018-06-07 16:16:40.541127+0100 crunch[8818:4200911] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    203. -> applicationWillResignActive()
    204. 2018-06-07 16:16:41.268314+0100 crunch[8818:4200901] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    205. 2018-06-07 16:16:41.275654+0100 crunch[8818:4200901] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    206. 2018-06-07 16:16:43.088824+0100 crunch[8818:4200638] UnityIAP: UpdatedTransactions
    207. 2018-06-07 16:16:43.089081+0100 crunch[8818:4200638] UnityIAP: PurchaseFailed: 2
    208. -> applicationDidBecomeActive()
    209. 2018-06-07 16:16:43.121289+0100 crunch[8818:4200902] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    210. onPurchaseFailedEvent({0}): ios.sp_evil.id
    211. UnityEngine.Purchasing.PurchasingManager:OnPurchaseFailed(PurchaseFailureDescription)
    212. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    213. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    214. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    215.  
    216. OnPurchaseFailed: FAIL. Product: 'ios.sp_evil.id', PurchaseFailureReason: UserCancelled
    217. Shop:OnPurchaseFailed(Product, PurchaseFailureReason)
    218. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    219. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    220. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    221.  
    222. Show AllCoroutinesKilled
    223. LoadingPanelManager:ShowPanel(Boolean)
    224. LoadingPanelManager:HidePanel()
    225. Shop:OnPurchaseFailed(Product, PurchaseFailureReason)
    226. UnityEngine.Purchasing.JSONStore:OnPurchaseFailed(PurchaseFailureDescription, String)
    227. UnityEngine.Purchasing.Extension.UnityUtil:Update()
    228. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    229.  
    230. [Crashlytics] Recording exception: FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    231. Fabric.Internal.Crashlytics.CrashlyticsInit:HandleLog(String, String, LogType)
    232. UnityEngine.LogCallback:Invoke(String, String, LogType)
    233. UnityEngine.Application:CallLogCallback(String, String, LogType, Boolean)
    234. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    235.  
    236. [Crashlytics] Exception stack trace: System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args)
    237. System.String.Format (IFormatProvider provider, System.String format, System.Object[] args)
    238. Shop.OnPurchaseFailed (UnityEngine.Purchasing.Product product, PurchaseFailureReason failureReason)
    239. UnityEngine.Purchasing.JSONStore.OnPurchaseFailed (UnityEngine.Purchasing.Extension.PurchaseFailureDescription failure, System.String json)
    240. UnityEngine.Purchasing.Extension.UnityUtil.Update ()
    241.  
    242. Fabric.Internal.Crashlytics.CrashlyticsInit:HandleLog(String, String, LogType)
    243. UnityEngine.LogCallback:Invoke(String, String, LogType)
    244. UnityEngine.Application:CallLogCallback(String, String, LogType, Boolean)
    245. (Filename: /Users/builduser/buildslave/unity/build/Runtime/Export/Debug.bindings.h Line: 43)
    246.  
    247. 2018-06-07 16:16:43.144089+0100 crunch[8818:4200904] You are using download over http. Currently Unity adds NSAllowsArbitraryLoadsFormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
    248.   at System.String.FormatHelper (System.Text.StringBuilder result, IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0
    249.   at System.String.Format (IFormatProvider provider, System.String format, System.Object[] args) [0x00000] in <filename unknown>:0
    250.   at Shop.OnPurchaseFailed (UnityEngine.Purchasing.Product product, PurchaseFailureReason failureReason) [0x00000] in <filename unknown>:0
    251.   at UnityEngine.Purchasing.JSONStore.OnPurchaseFailed (UnityEngine.Purchasing.Extension.PurchaseFailureDescription failure, System.String json) [0x00000] in <filename unknown>:0
    252.   at UnityEngine.Purchasing.Extension.UnityUtil.Update () [0x00000] in <filename unknown>:0
    253. (Filename: currently not available on il2cpp Line: -1)
    254.  
    255. 2018-06-07 16:16:43.173676+0100 crunch[8818:4200902] You are using download over http. Currently Unity adds NSAllowsArbitraryLoads to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    256. to Info.plist to simplify transition, but it will be removed soon. Please consider updating to https.
    257.  
     
  6. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
    I would suggest that you use Debug.Log statements and run the app within the Editor to see if you are initializing IAP twice, or similar unexpected behavior. Is your click event getting fired on each scene reload, for example? Can you use the Sample Project here to create a scenario that we can use to test with? Which game object are you attaching the script to? If you look at the sample project code, the singleton m_storecontroller is in the script that is attached to a game object that is never destroyed. It appears that you are attempting to create your singleton local to the scene.
     
    Last edited: Jun 7, 2018
  7. LimeJuice

    LimeJuice

    Joined:
    Nov 8, 2012
    Posts:
    58
    Thanks, I did track the issue with Debug.Log and it seems like my singleton receive the event twice even tho the object emitting the event does it only once. I think my singleton fails to unsubscribe to events. So when the scene is reloaded, it does get called twice or more depending of how many time the scene has been reloaded.

    I am not sure why it did not unsubscribe properly... or maybe there is some behaviours related to singletons and event that I don't understsand.

    Here the relevant code on the singleton:

    Code (CSharp):
    1.  
    2. public class Shop : MonoBehaviour, IStoreListener {
    3.  
    4.     public void Awake() {
    5.  
    6.                 // SINGLETON
    7.                 if (the_shop_instance == null) {
    8.  
    9.                         //if not, set instance to this
    10.                         the_shop_instance = this;
    11.                 }
    12.                 //If instance already exists and it's not this:
    13.                 else if (the_shop_instance != this){
    14.  
    15.                         //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
    16.                         Destroy (gameObject);
    17.                 }
    18.                 //Sets this to not be destroyed when reloading scene
    19.                 DontDestroyOnLoad(gameObject);
    20.  
    21.                 print("Shop Subscribe to events");
    22.            
    23.  
    24.                 shop_item.EventOnPressBuyWCash += Purchase;
    25.  
    26.         }
    27.  
    28.             void  OnDisable(){
    29.         print("Shop UnSubscribe to events");
    30.  
    31.                  shop_item.EventOnPressBuyWCash -= Purchase;
    32.  
    33.             }
    34. }
    And the code on the script that with the function called when I press the button:

    Code (CSharp):
    1.  
    2. public class shop_item : MonoBehaviour {
    3.  
    4.         public delegate void OnPressBuyWCash (int ID);
    5.         public static event OnPressBuyWCash  EventOnPressBuyWCash;
    6.  
    7.         public void PressBuyWCash(){
    8.  
    9.                 EventOnPressBuyWCash (ItemID);
    10.                 }
    11. }
    12.  
    Any idea on how to avoid these call being called multiple time when the scene is reloaded?
     
    Last edited: Jun 26, 2018