Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by immodiumvash · Mar 05, 2018 at 07:18 PM · c#iapcollections

IAP button gives error : InvalidOperationException: Collection was modified

Hi Everyone, Im getting this error every time i click on an IAP button in my game :

"InvalidOperationException: Collection was modified; enumeration operation may not execute."

and it does not reference any code in the game, it all seem to be an error in the code of the Unity IAP. the buttons were fine before I updated the IAP package.

now when i click an IAP button to buy an item in my game the editor pauses for this error, but if I unpause it it continues normaly as if the button worked. I dont know what to do as the error is not in my code. can I go back to an IAP earlier code.?

help please.

Thank you.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Chik3r · Mar 07, 2018 at 09:57 PM 0
Share

Can you show us your iap initialization code, and the buying code

3 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by jamesk5 · Mar 28, 2018 at 10:29 PM

To follow my comment above, I found the answer (for me, at least).

This was happening because I was deactivating the UI where the IAP button was nested. Makes sense to deactivate your custom-purchase-confirmation-window (gameObject) when the purchase was completed, right? Well it throws this error.

Solution:

Inside your Purchase Complete and Purchase Failed callbacks (the functions you assign in the inspector), don't deactivate the IAP button (or its parent via hierarchy). Instead, put that deactivate-code into a separate function that you Invoke after 0.1 seconds. This lets the IAP button finish its business before it gets deactivated via the hierarchy.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image immodiumvash · Apr 02, 2018 at 11:40 PM 0
Share

Nice solution $$anonymous$$an!, well unity did replicated the error, and its investigating it now as they tell me.

now I just replaced the IAP package with and older one I had in backup (gotta always have backups!).

if it happens again, I´ll know what to do. thanks!

avatar image Kiwasi · May 25, 2018 at 11:25 PM 2
Share

You can also use a coroutine and just wait a single frame. Also seems to work.

avatar image briosh · Aug 23, 2019 at 09:03 AM 0
Share

That was it! Thanks! Ins$$anonymous$$d of disabling game object you can simply disable the component image or button or the canvas group that contains it. This can happen instantly without problem.

avatar image gustavofournier · May 06, 2021 at 03:48 AM 0
Share

This solution works for me, thanks!!!

avatar image selfdefiant · Jul 21, 2021 at 06:52 PM 0
Share

That worked for me, many thanks!

avatar image
0

Answer by MacDx · Mar 07, 2018 at 10:37 PM

That error usually pops whenever you erase/add elements from/to a list that you are iterating over. Example:

 foreach(Foo foo in fooList)
 {
     if(foo.shouldBeRemoved)
         fooList.Remove(foo);
 }

This will give error since you are shortening the list while iterating over it, which can give unexpected results. If that's the case what you can do is save whatever objects you want to delete inside a new list and then iterate over that list, deleting them from the original list.

 List<Foo> fooToRemove = new List<Foo>();
 foreach(Foo foo in fooList)
 {
     if(foo.shouldBeRemoved)
         fooToRemove.Add(foo);
 }
 foreach(Foo foo in fooToRemove)
 {
     fooList.Remove(foo);
 }
 //You'd take the same approach for adding new elements

That's my guess, however the only way I can be sure that this is the exact problem is if I take a look at your code.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image immodiumvash · Mar 07, 2018 at 11:33 PM 0
Share

Thanks for the answer man! , I get what the error is about, but its not in my code, I could not show you as is a code Im guessin of the unity IAP package. It happens when I click on a unity codeless IAP Button.

Ill post the exact error when I get home. Thank you very much @$$anonymous$$acDx !

avatar image
0

Answer by immodiumvash · Mar 09, 2018 at 07:36 AM

this is the error @chiker and @MacDx:

InvalidOperationException: Collection was modified; enumeration operation may not execute. System.Collections.Generic.List`1+Enumerator[UnityEngine.Purchasing.IAPButton].VerifyState () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:778) System.Collections.Generic.List`1+Enumerator[UnityEngine.Purchasing.IAPButton].MoveNext () (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/List.cs:784) UnityEngine.Purchasing.IAPButton+IAPButtonStoreManager.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at Assets/Plugins/UnityPurchasing/script/IAPButton.cs:328) UnityEngine.Purchasing.StoreListenerProxy.ProcessPurchase (UnityEngine.Purchasing.PurchaseEventArgs e) (at C:/buildslave/unity/build/Extensions/UnityPurchasing/Runtime/Purchasing/StoreListenerProxy.cs:34) UnityEngine.Purchasing.PurchasingManager.ProcessPurchaseIfNew (UnityEngine.Purchasing.Product product) (at C:/buildslave/unity/build/Extensions/UnityPurchasing/Runtime/Purchasing/PurchasingManager.cs:212) UnityEngine.Purchasing.PurchasingManager.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionId) (at C:/buildslave/unity/build/Extensions/UnityPurchasing/Runtime/Purchasing/PurchasingManager.cs:115) UnityEngine.Purchasing.JSONStore.OnPurchaseSucceeded (System.String id, System.String receipt, System.String transactionID) UnityEngine.Purchasing.FakeStore.<>n_0 (System.String id, System.String receipt, System.String transactionID) UnityEngine.Purchasing.FakeStore+<>cDisplayClass15_0.b0 (Boolean allow, PurchaseFailureReason failureReason) UnityEngine.Purchasing.UIFakeStore+<>cDisplayClass14_0`1[UnityEngine.Purchasing.PurchaseFailureReason].b0 (Boolean result, Int32 codeValue) UnityEngine.Purchasing.UIFakeStore.OkayButtonClicked () UnityEngine.Purchasing.UIFakeStore.b_16_1 () UnityEngine.Events.InvokableCall.Invoke (System.Object[] args) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:154) UnityEngine.Events.InvokableCallList.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:637) UnityEngine.Events.UnityEventBase.Invoke (System.Object[] parameters) (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:773) UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:52) UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:35) UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:44) UnityEngine.EventSystems.ExecuteEvents.Execute (IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50) UnityEngine.EventSystems.ExecuteEvents.Execute[IPointerClickHandler] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.EventFunction`1 functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261) UnityEngine.EventSystems.EventSystem:Update()

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MacDx · Mar 09, 2018 at 05:19 PM 0
Share

So, neither IAPButton.cs, nor StoreListenerProxy.cs nor Purchasing$$anonymous$$anager.cs are yours right? Is there literally not a single one of your classes involved in this whole process? Because if it is so, then the error should be on the plugin side and you'd want to contact the developers. Are you passing any data whatsoever to this process?

avatar image immodiumvash MacDx · Mar 10, 2018 at 06:22 PM 0
Share

Exaclty, its not my code in anyway. those buttons just unlock items, the only thing I pass is the result of the purchase witch just change a playerpref key and this works fine cose after I unpause the error in the editor everything its ok.ther was no error before the last update of the IAP Package. @$$anonymous$$acDx

avatar image MacDx immodiumvash · Mar 10, 2018 at 08:40 PM 0
Share

Yup, I think your best bet is to report this to the developers of this package.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

462 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Dictionary suddenly loses its items 1 Answer

Windows Universal IAP 0 Answers

Initialising List array for use in a custom Editor 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges