yandexmobile / metrica-plugin-unity

Unity plugin for Yandex AppMetrica SDK
38 stars 18 forks source link

Need IsActivated() method #35

Closed mana-break closed 3 years ago

mana-break commented 3 years ago

How can I check if it is already possible to send events? Now, when sending events early, the application throws an exception. Need IsActivated() method.

GLinnik21 commented 3 years ago

Hello! There are no such methods even in native SDKs. Do you send an event right after activation on the same thread? If not, I guess you have to synchronize this whole process yourself.

mana-break commented 3 years ago

In Unity, the order of initialization of game objects on the scene is undefined. I use the main thread. Other objects can send events before AppMetrica was activated and I can't check it. I can only catch exceptions.

GLinnik21 commented 3 years ago

AppMetrica activates in the Awake method. You cannot send events from the Awake method from other objects, because there is no guarantee that AppMetrica was previously activated. But you can begin sending events from Start methods. If this is not the case, make sure to add Prefab to the scene. If you need to send events from Awake, then you have to activate AppMetrica yourself before sending events using AppMetrica.Instance.ActivateWithConfiguration ().