firebase / firebase/firebase-unity-sdk

Remove Listeners not working

Open
#371 13 comments 0 reactions 0 assignees View on GitHub
api: database type: bug
Dominant language
C#
Stars
320
Forks
60
Avg merge
13h 32m
Merged PRs (30d)
13

Description

### Please fill in the following fields:
Unity editor version: 2019.3
Unity Firebase SDK: 6.9.0
Firebase plugins in use: Database
Platform you are using the Unity editor on: Mac
Platform you are targeting: iOS, Android

### Please describe the issue here:
I have basic listeners getting data from database. Looking like this

```
void StartListener () {

FirebaseDatabase.DefaultInstance
.GetReference ("Main")
.ValueChanged += ListenForServerTimestamp;
}
```

I am removing them here

```
void OnDisable () {

FirebaseDatabase.DefaultInstance
.GetReference ("Main")
.ValueChanged -= ListenForServerTimestamp;
}
```

The issue is that removing is not working. Actualy removing listeners like this is adding them again instead of removing them. When i run the code like this and go to next scene and back i receive 3 calls. When i remove the OnDisable, i get the call only 2 times.
Any idea why removing listeners is not working? I am not sure if its affected by the fact that i am loading other scene and then going back.

Also, only way i am able to disable the listeners to constantly fire even when the editor is not playing is by forcing Firebase to go completely offline with this

` FirebaseDatabase.DefaultInstance.GoOffline (); `

I realy dont know how else to handle it. I could not find anything on how to properly handle listeners in the samples. It would be great if there was some example, how to add/remove listeners over multiple scenes. I also did not find any example how to work with Firebase in Unity in general over multiple scenes. It seems the example always consider only one scene, while Firebase seems to be very persistent over all scenes and even when the app is disabled ( or editor is turned off ).

Thanks

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the StartListener and OnDisable lifecycle across scene changes with FirebaseDatabase.DefaultInstance and the Main reference. Inspect how ValueChanged subscriptions behave when the Unity object or scene is disabled, including the reported GoOffline workaround. Done means the listener can be added and removed reliably across scenes, or the expected lifecycle and a documented example are provided.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.