firebase / quickstart-unity

Firebase Quickstart Samples for Unity
https://firebase.google.com/games
Apache License 2.0
819 stars 424 forks source link

Can't unsubscribe from events? #1319

Closed yogev2255 closed 1 year ago

yogev2255 commented 1 year ago

[REQUIRED] Please fill in the following fields: Unity editor version: 2021.3.15f1 Firebase Unity SDK version: 10.3.0 Source you installed the SDK: _.unitypackage _ (.unitypackage or Unity Package Manager) Problematic Firebase Component: database (Auth, Database, etc.) Other Firebase Components in use: non (Auth, Database, etc.) Additional SDKs you are using: GooglePlay (Facebook, AdMob, etc.) Platform you are using the Unity editor on: _windows (Mac, Windows, or Linux) Platform you are targeting: android (iOS, Android, and/or desktop) Scripting Runtime: IL2CPP (Mono, and/or IL2CPP) [REQUIRED] Please describe the issue here:

Hello,

I use firebase real-time database and I am subscribing to events on start and a few other places and is working fine

but when I am trying to unsubscribe from them in OnDisable the user still receives updates from firebase why? I get this on 2 different scripts

I tested with [ContextMenu("disable")] void RemoveEvents() { db.Child("Users").Child(GameManager.instance.pinCode.ToString()).ChildAdded -= AddPlayerToList; db.Child("Users").Child(GameManager.instance.pinCode.ToString()).ChildRemoved -= RemovePlayerList; db.Child("Servers").Child(GameManager.instance.pinCode.ToString()).ChildChanged -= OnServerChagne; Application.quitting -= UserQuitTheGame; StopAllCoroutines(); Debug.Log("disable lobby"); } but I still receive events

google-oss-bot commented 1 year ago

This issue does not seem to follow the issue template. Make sure you provide all the required information.

jonsimantov commented 1 year ago

Hi,

I've managed to reproduce this issue when unsubscribing events from a new DatabaseReference created with the same path as the old DatabaseReference.

As a workaround, if you hold onto the actual DatabaseReference instances that you registered the events on, you should be able to unsubscribe from them.

yogev2255 commented 1 year ago

Thank you, it worked for me