How to wait for a specific Event in a c++ function

Hello everyone,
I’m new with unreal engine and I try to code a system of Pop Up for my first game. My code :

  • I have a function which creates a Pop Up and add it to viewport.


if (CurrentWidget != nullptr)
    {
        CurrentWidget->RemoveFromViewport();
        CurrentWidget = nullptr;
    }
    if (DonneGorgeeWidgetClass != nullptr)
    {
        CurrentWidget = CreateWidget<UDonneGorgeeWidget>(GetWorld(), DonneGorgeeWidgetClass);

        CurrentWidget->setNbGorgees(m_nbGorgee);
        CurrentWidget->setPirate(perso);

        if (CurrentWidget != nullptr)
        {
            CurrentWidget->AddToViewport();
        }
    }


  • I have created my own Widget Class in order to pass parameters like “m_nbGorgee” and “perso” and then the pop up appears. There is a sequence of three pop ups before the last pop up.
    Then I would like to wait for the user to close the last pop up before continuing the code like this :


void do()
{
    m_popupFinished = false;

    if (CurrentWidget != nullptr)
    {
        CurrentWidget->RemoveFromViewport();
        CurrentWidget = nullptr;
    }
    if (DonneGorgeeWidgetClass != nullptr)
    {
        CurrentWidget = CreateWidget<UDonneGorgeeWidget>(GetWorld(), DonneGorgeeWidgetClass);

        CurrentWidget->setNbGorgees(m_nbGorgee);
        CurrentWidget->setPirate(perso);

        if (CurrentWidget != nullptr)
        {
            CurrentWidget->AddToViewport();
        }
    }

    while (!m_popupFinished); //Or maybe wait for an event because a while loop will consume resources

    // Do other stuffs

    return;
}


My problem is I don’t know how to interact with the last pop up widget to tell this function to pass the while loop. I’ve heard about Event Dispatcher but I don’t know if it is the good solution.
If someone have a good and elegant solution !
Thank You