event is called twice

I am trying to send an event that activates the Save method on another script. But for some reason, it seems like the event is called twice.
(I currently call another method to test the code more easily)

    public delegate void SaveDataTrigger();
    public static event SaveDataTrigger SaveTheData;

    public void CloseShop() {
        SaveTheData();
        SceneManager.LoadScene("MainMenu");
    }

// other class

        ShopManager.SaveTheData += Say;

    public void Say() {
        Debug.Log("hi");
    }

this are the relevant parts of the code. The closeShop method is only called once, i tested it with Debug.Log(). But “hi” is printed twice.
Maybe someone knows why this happens?

Edit: I tested again, and it turns out, that during one session, every time i click the button that call the CloseShop() method, the amount of times “hi” is Say() is executed, is raising by two.

It sounds like you are adding the event handler twice i.e. doing ShopManager.SaveTheData += Say; twice.


You could log out the length of the invocation list and to see if its greater than 1.