In **Unity**, after importing **UnityIAP Version: 2.3.0**, I have a **button** to which I attached an **IAP Button** component like in the image below:

[![enter image description here][1]][1]


My **SkinsPanel** class looks like this:

    using System.Collections.Generic;
    using DG.Tweening;
    using UnityEngine;
    using UnityEngine.Purchasing;
    
    public class SkinsPanel : MonoBehaviour
    {
        [SerializeField] private RectTransform SorcererPurchaseButton; //reference to the button that is being pressed
        private string sorcererID = "com.company.test.sorcererID";
    
        public void OnPurchaseComplete(Product product)
        {
            if (product.definition.id == sorcererID)
            {
                SorcererPurchaseButton.gameObject.SetActive(false);
                //SorcererPurchaseButton.DOAnchorPos(new Vector2(1000, 1000), 0f);
            }
        }
    
        public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
        {
            Debug.Log("Failed");
        }
    }

Nothing incredible complicated, a reference to the **button** and two functions: **OnPurchaseComplete** and **OnPurchaseFailed**.

Now, if the user completes the purchase succesfully:

[![enter image description here][2]][2]

I'm getting a **Collection was modified; enumeration operation may not execute.** error:

[![enter image description here][3]][3]

I understand this issue would be caused if I were to iterate over a collection with something like a **foreach** and modifying/removing the elements over the iteration.

If I were to to simply change the position of the button like:

    //SorcererPurchaseButton.gameObject.SetActive(false);
    SorcererPurchaseButton.DOAnchorPos(new Vector2(1000, 1000), 0f);

this would work without any issues.

What is the issue here? Is it some Unity IAP bug?

  [1]: https://i.sstatic.net/7BYQh.png
  [2]: https://i.sstatic.net/g6itk.png
  [3]: https://i.sstatic.net/Zi4D6.png