question

Maarten Braaksma avatar image
Maarten Braaksma asked

PlayFabHTTP destruction

Hi!

I'm curious what exactly can cause the PlayFabHTTP script to destroy.

The reason why I'm asking this is that PlayFabHTTP is being destroyed a couple of ms after starting my build, which results in not finishing the coroutines and thus the WebRequests.

I have logged this, but it's not a scene change that's causing this. PlayFabHTTP can't be destroyed, because it's a DontDestroyOnLoad object.

I hope someone here can help me out fixing this issue.

Thanks in advance!

EDIT:

I'm using PlayFab SDK version 2.136.220523

This destroy issue does not happen in-editor, but it does happen in-build. Doesn't matter if it's IL2CPP or Mono or if Stripping Code is minimal.

UPDATE 02.06.2022:

I've tried reproducing it in an empty project with the PlayFab SDK in it.

The PlayFab calls would be called with this attribute: [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]

This means that before the first scene has been loaded, PlayFabHTTP had to call the WebRequest already.

Now the thing is, is that PlayFabHTTP doesn't like that and just destroys itself because of that, even if it's DontDestroyOnLoad.

If we're not using that attribute and we make sure the script is a MonoBehaviour, it works fine.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kaj avatar image
kaj answered

I found the reason for this, it has something to do with Unitys scene loading logic.

I tried to re-create the issue with an empty Unity project without Play-fab, the reproduction steps are simple.

1. Create callback attached to: [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]

2. Spawn a GameObject within this callback

3. The newly spawned GameObject will be deleted when Unity loads the first scene in the build settings.

I am not sure why this is happening, but it seems Unity destroys GameObjects that are spawned before an actual scene is loaded, DontDestroyOnLoad does not work in this case, and the object is still destroyed by Unity.

We avoided this issue by shifting the BootLoader initialization from the Unity splash screen to the point where the first scene in the build settings is loaded, the game now starts slower, but it is a work-around for the issue.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Gosen Gao avatar image
Gosen Gao answered

After doing some tests, I think this issue may be related to asynchronous calls. Since PlayFab APIs are asynchronous, it is recommended that you consult Unity to see whether the asynchronous requests called in this process of the life cycle can be successfully completed if unity enters the next process of the life cycle.

In my tests, the PlayFab API can complete successfully if I manually wait a period of time(A second). This might be a workaround.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.