Question

Example scripts throws null reference exception in Unity3D

  • 1 August 2023
  • 2 replies
  • 51 views

Badge +6

I’m using Unity3D 2021.3.27f1 and Revenue Cat Unity SDK 4.16.0 (also tried with 5.0.0-alpha.1).

 

I have simple empty scene with single object called Revenue Cat with two components. 1st is the Purchases component and second is the implementation of Purchases.UpdatedCustomerInfoListener that I called RevenueCatListener. It’s just copy paste from SDK installation instructions on official docs.

The problem is that on Start i’m getting two null references: 1st one when code reachs SetLogLevel function invoke and second when I try to fetch products. 

 

I debug it and found that _wrapper that created in Purchases component is null during thins invocations. And this is very logical, because bwrapper created at Start and SetLogLevel \ FetchProducts (Offers) in docs example are at Start. So because Unity Start invocation order isn't guaranteed by default, we have wrong invocation order and null references.

 

My question is how it’s possible that there is SUCH big problem in default examples of SDK? May be it’s me who understand something wrong? Why event at ste start docs having such troubles, what we can expect next?


2 replies

Badge +6

I think question was ritorical. Solution is to add [DefaultExecutionOrder(1)] to the class that implements Purchases.UpdatedCustomerInfoListener. 

 

It will be nice to add this in docs for Unity 3d.

Userlevel 6
Badge +8

Hey @rastleks,

Thanks for the feedback, and I’m glad you were able to resolve this. We’ll aim to make these docs simpler and try to be more clear about the examples.

Reply