- Home /
Unity IAP InitializePurchasing taking too long.
Hello,
In my Unity application I am using Unity Purchasing module and I have basically a store.
By now we have 1000+ different in-apps and we continue adding more everyday.
At the beginning I am calling “InitializePurchasing” with a builder that has all the possible in-apps, but the problem is that it usually takes around a minute to finish the initialisation and I guess the more inapps we add - the longet it will take.
At the beginning in my store user can see up to 50 “Highlighted” items and usually users stay on this page for some time (enough to initialise all the other in app purchases).
What are the good practices to handle this problem?
I was thinking about a few ways:
Initiallize Highlighted items first and then start the initialisation of the whole store.
Initialise only those items that are on screen (usually 50), so that when switches page or changes browse filters - I re-initialise the store.
Initialise only those items that are on screen (usually 50), so that when switches page or changes browse filters - I re-initialise the store.
Initialise only one purcahse that user wants to buy on “Buy” button press.
Other way.
Thank you for your answers and comments.
Answer by nicholasr · Jul 12, 2016 at 06:52 PM
Hi @bkachmar!
In Unity 5.4 we added a new API to handle fetching products incrementally:
Unity 5.4 release candidate is coming very soon - and the beta is already available. Will this work for you?
Nick
Hello @nicholasr,
Thanks a lot, I guess this will be the best option possible. Do you have any information on how long does that "very soon" take?
Best, Bohdan
Re: Soon, sorry, not much more detail than "soon". It's based upon our QA progress. Hopefully weeks.
http://www.dumpaday.com/wp-content/uploads/2013/01/soon-polar-bear-and-seal.png
And one more thing,
How would you recommend adding 3 000 in app purchases: - One by one; - In groups of 100 - At the beginning initial 100 and then all the others?
$$anonymous$$y opinion would be to see if groups of 100 creates the experience you want. Or perhaps 50.
Not size=1, and not size=1000, since I believe those will both be slower than you want.
But my "100 or 50" are guesses, and of course their performance may vary depending upon network conditions, etc.
Please if you do decide on "The Best Size" post it here, and I'll repeat it to others! :)
Ok, I will post it "soon", when this will be released in stable version =)
@nicholasr Is there any way to get the new IAP version without downloading the whole beta version?
@davidb1 One must download Unity 5.4 (https://unity3d.com/unity/beta as of writing this) and its newer UnityEngine.Purchasing.dll
file to use the newer feature today. The feature has not been backported to Unity 5.3.x.
Hello,
So I downloaded second release candidate of Unity 5.4.0f2 and made everything this way: - I take first 50 purchases that appear on first screen, create a ConfigurationBuilder with those and initialize store. - On Initialized I remember IStoreController and IExtensionProvider and while I have more purchases available repeat next step - Wait one frame, create HashSet with next 50 inapps and FetchAdditionalProducts with that HashSet.
I tried to init in groups of 50 and in groups of 100 (I have around 1300 inapps) and it took {89.9, 85.8, 70.0, 74.3} seconds for 50-piece groups and {116.7, 72.23, 86.7, 83.3} seconds for 100-piece groups.
But purchasing doesn't work now. If I don't fetch new products the initial 50 can be purchased easily, but if I fetch more, neither first 50 nor others work =(
This is how my code looks like:
ConfigurationBuilder builder = ConfigurationBuilder.Instance(StandardPurchasing$$anonymous$$odule.Instance());
foreach (string highlightedId in highlightedIds)
{
builder.AddProduct(highlightedId, ProductType.NonConsumable);
}
UnityPurchasing.Initialize(this, builder);
and after OnInitialized is called I wait one frame fill new HashSet with
itemsHashSet.Add(new ProductDefinition(allIds[i], ProductType.NonConsumable));
and call the fetch function
m_StoreController.FetchAdditionalProducts(itemsHashSet, OnProductsFetched, OnInitializeFailed);
All IDs display as expected in xCode and looks like everything is good, but when I test on device I get "ArgumentException: The requested value 'ItemUnavailable' was not found.".
I can see that my product is availableToPurchase and metadata is filled, but purchasing doesn't work. And again I I do not fetch additional products after I initialize store with first 50 inapps they work, but when I start fetching everything gives this exception.