Skip to content

Remove Listeners not working #371

Open
@LukePenkava

Description

@LukePenkava

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions