question

Travis Lange avatar image
Travis Lange asked

Why does Unity GSDK PlayFabAgentView destroy on load when Unity changes scenes?

It seems to me that the PlayFabAgentView should be set to DontDestroyOnLoad so that it can continue to communicate with ThunderHead even when it changes scenes. Currently we do this:

PlayFabMultiplayerAgentAPI.Start();
DontDestroyOnLoad(GameObject.Find("PlayFabAgentView"));

It would make more sense to be to do something like:

bool dontDestroyAgentViewOnLoad = true;
PlayFabMultiplayerAgentAPI.Start(dontDestroyAgentViewOnLoad);

What do you think of this? Is there a reason it currently gets destroyed on load? If not, are pull requests open? I can create one for everyone at PlayFab to review and don't mind.

unity3dsdks
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

·
brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

We haven't tested loading/unloading networked scenes, but I think you're right that presumably it's best to avoid Starting/Restarting the Agent API every time a new scene loads. Theoretically, as long as the "agentView" GameObject is created as a Singleton, it will be able to access the static instance of the Agent API.The main reason I'd do it as a Singleton instead of DontDestroyOnLoad() would be in case you return to the initial scene, you'd have potentially two instances of AgentView components.

Although I suppose you could also just create an "agentView" GameObject with the PlayFabMultiplayerAgentView component on each networked scene, and have your Network Manager update the Agent API with the current instance of the AgentView component every time a networked scene loads.

3 comments
10 |1200

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

Travis Lange avatar image Travis Lange commented ·

If you look at the PlayFabMultiplayerAgentAPI.Start() method, you will see that the API does already create the GameObject and add the PlayFabAgentView component too it. PlayFab already has that scripted in. I agree that a singleton would be much better. If PlayFab is taking pull requests right now, I'd be more than happy to create it.

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Travis Lange commented ·

You can try to create a pull request and please add the reasons why you need to add this feature in the GSDK. Or you can try to add a feature request for this feature that adding native support to not destroy PlayFabMultiplayerAgentView on loading scenes.

0 Likes 0 ·
Travis Lange avatar image Travis Lange Sarah Zhang commented ·

Awesome! Will do! :)

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.