Firebase Unity fails to receive events after Scene Transition (workaround and fix)

180 views
Skip to first unread message

c.santa...@brbent.com

unread,
Nov 22, 2016, 6:08:54 PM11/22/16
to Firebase Google Group
Firebase is creating a GameObject that simultaneously marshals the C++ events into C# and makes the resulting event fire within the Unity thread, this is done under the hood as soon as the App library is initialized via lazy-loading. Unfortunately that GameObject is never set to DontDestroyOnLoad, so it is being unloaded upon a scene transition. If you have succeeded in getting Firebase to receive events in your Unity project, but events stop being received after a scene transition, this is why.

User Work Around:
Call "GameObject.DontDestroyOnLoad(GameObject.Find("Firebase Services"));" after you first reference the Firebase library that you are using. You could also re-parent it to an existing DontDestroyOnLoad object.


For the Firebase Team: 
This could be fixed by adding "GameObject.DontDestroyOnLoad(firebaseHandler);" to the end of FirebaseHandler::Create. 

However, it might be better to package the Firebase Services gameobject as a Prefab that the user drops into their scene, or to expose the FirebaseHandler class as public so that it can be put onto a DontDestroyOnLoad "master object" explicitly. Having a GameObject mysteriously appear in the hierarchy could cause issues for some projects; plus, it is nice being able to know exactly what objects are in your scene, when they are being created, when they are being destroyed, and why they are there. 

Cheers!
-Chance

Stewart Miles

unread,
Nov 22, 2016, 6:56:49 PM11/22/16
to fireba...@googlegroups.com
Hi Chance,

Thanks for the bug report.  I think we would prefer to just add the GameObject.DontDestroyOnLoad() call instead.  The "Firebase Services" gameobject is really a workaround for the way we have to route callbacks in Unity so we would prefer to not expose this as part of the public API surface.  We'll get this in our queue for our next release.

Cheers,
Stewart

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fe5b559d-56fe-4a3d-8a4f-0cfbe895183d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stewart Miles

unread,
Dec 9, 2016, 4:20:38 PM12/9/16
to Firebase Google Group
I'm pleased to announce that we released:
  • Firebase C++ SDK 2.1.0 (release notes here, download here)
  • Firebase Unity SDK 1.1.0 (release notes here, download here)
We hope this resolves your issue.  If not, please let us know and we'll take a look.

Cheers,
Stewart
Reply all
Reply to author
Forward
0 new messages