question

contrejo27 avatar image
contrejo27 asked

How do you make sure commands are sent before Unity Quits?

Right now when I call the player to set an object on OnApplicationQuit() says I must be logged in Playfab to do that command. It seems it's logging out before OnApplicationQuit is called. is there anything that would do that in Playfab? I don't think anything in my code does that.

For reference here's an object I'm setting and what I'm calling in OnApplicationQuit.


PlayFabDataAPI.SetObjects(new SetObjectsRequest()
{
    Entity = new EntityKey { Id = player.titleAccountId, Type = titleEntityType }, // Saved from GetEntityToken, or a specified key created from a titlePlayerId, CharacterId, etc
    Objects = dataList,
}, (setResult) =>
{
    print("Setting online status to " + onlineStatus);

}, DisplayPlayFabError);
public void OnApplicationQuit()
{
    ChallengeController.Controller.CancelChallenge(player.titleAccountId);
    SetOnlineStatus(ConnectionStatus.Disconnected);
}
entities
10 |1200

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

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

After doing some tests, we found that we can’t reproduce the issue if we only call API SetObjects in OnApplicationQuit. No error occurred, and the data updated successfully. The error you mentioned occurs when the EntityToken is missing. If we manually remove the EntityToken, we can reproduce this issue. I would suggest you print the EntityToken before the API SetObjects to see if this is the reason. EntityToken should be stored at PlayFabSettings.staticPlayer.EntityToken.

1 comment
10 |1200

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

contrejo27 avatar image contrejo27 commented ·

Thank you. I'll check it out, I did a temp fix that waits half a second before quitting and Im not getting the error but I'll check again once I get back to that part.

0 Likes 0 ·

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.