AsyncTask() has the Wrong Reference Values

So, basically, I am running some lines of code inside of AsyncTask() with the use of a Lambda (Which I just learned a few days ago, so I am super new to it.)

In short, I have a const bool isSomething which gets assigned to True. The UE_LOG shows me that it is indeed 1. Then, the AsyncThread()'s UE_LOG shows up saying that the isSomething variable is False, outputting a 0. I have no idea why this is happening, as I pass the values by reference in [&].

Callback from USteamManager

void USteamManager::OnSteamOverlayActive(GameOverlayActivated_t *pCallbackData)
{
	UE_LOG(LogSteamworks, Warning, TEXT("Yay! Intercepted the Steam overlay callback"));
	const bool isCurrentOverlayActive = ((pCallbackData->m_bActive) != (0));;
	UE_LOG(LogSteamworks, Log, TEXT("isCurrentOverlayActive = %d"), isCurrentOverlayActive);
	MusicalRangeGameInstance;
    	
	AsyncTask(ENamedThreads::GameThread, [&]() {
		UE_LOG(LogSteamworks, Log, TEXT("Running inside AsyncTask()"));
		UE_LOG(LogSteamworks, Log, TEXT("Calling PublicOnSteamOverlayIsActive from SteamManager"));
		MusicalRangeGameInstance->PublicOnSteamOverlayIsActive(isCurrentOverlayActive);
		UE_LOG(LogSteamworks, Log, TEXT("Exiting AsyncTask()"));
	});

	UE_LOG(LogSteamworks, Log, TEXT("OnSteamOverlayActive() at SteamManager Finished"));
}

UMusicalRangeInstance to activate a Blueprint Event Node

void UMusicalRangeInstance::PublicOnSteamOverlayIsActive(bool isOverlayActive) {
	UE_LOG(LogSteamworks, Log, TEXT("PublicOnSteamOverlayIsActive Called"));
	UE_LOG(LogSteamworks, Log, TEXT("isOverlayActive = %d"), isOverlayActive);
	UE_LOG(LogSteamworks, Log, TEXT("IsSteamOverlayActive = %d"), IsSteamOverlayActive);
	if (IsSteamOverlayActive != isOverlayActive) //Only fire OnSteamOverlayIsActive() if NEW boolean is different than registered boolean
	{
		UE_LOG(LogSteamworks, Log, TEXT("IsSteamOverlayActive Different Than IsOverlayActive. Copying IsOverlayActive into IsSteamOverlayActive"));
		IsSteamOverlayActive = isOverlayActive;
		UE_LOG(LogSteamworks, Log, TEXT("Calling OnSteamOverlayIsActive using this->"));
		this->OnSteamOverlayIsActive(IsSteamOverlayActive);
		//OnSteamOverlayIsActive(IsSteamOverlayActive);
		UE_LOG(LogSteamworks, Log, TEXT("OnSteamOverlayIsActive Has been triggered"));
	}
	else
	{
		this->OnSteamOverlayIsActive(isOverlayActive);
		UE_LOG(LogSteamworks, Log, TEXT("IsSteamOverlayActive Equals IsOverlayActive. Nothing is executed"));
	}
}

And the Full output from the game. Which is triggered when I bring up the Steam Overlay.

[2017.04.02-02.18.51:045][627]LogSteamworks:Warning: Yay! Intercepted the Steam overlay callback
[2017.04.02-02.18.51:045][627]LogSteamworks: isCurrentOverlayActive = 1
[2017.04.02-02.18.51:045][627]LogSteamworks: OnSteamOverlayActive() at SteamManager Finished
[2017.04.02-02.18.51:045][627]LogSteamworks: Running inside AsyncTask()
[2017.04.02-02.18.51:045][627]LogSteamworks: Calling PublicOnSteamOverlayIsActive from SteamManager
[2017.04.02-02.18.51:045][627]LogSteamworks: PublicOnSteamOverlayIsActive Called
[2017.04.02-02.18.51:045][627]LogSteamworks: isOverlayActive = 0
[2017.04.02-02.18.51:045][627]LogSteamworks: isOverlayActive = 0
[2017.04.02-02.18.51:045][627]LogBlueprintUserMessages: [BP_MusicalRangeInstance_C_0] Steam Overlay Event Trigger: false
[2017.04.02-02.18.51:045][627]LogSteamworks: IsSteamOverlayActive Equals IsOverlayActive. Nothing is executed
[2017.04.02-02.18.51:045][627]LogSteamworks: Exiting AsyncTask()

Thanks!

Edit. Corrected AsyncThread() to AsyncTask().

Edit 2. I just tried adding to the AsyncTask() the following

AsyncTask(ENamedThreads::GameThread, [isCurrentOverlayActive, &MusicalRangeGameInstance]() {

And it failed to compile. I based on this reference. http://en.cppreference.com/w/cpp/language/lambda Where it said the capture list could be [a, &b], to copy the bool value of isCurrentOverlayActive but pass a reference of MusicalRangeGameInstance.

After reading the log more carefully, I noticed that the function OnSteamOverlayActive() ends before the AsyncTask() is executed. What I suspect is happening is that by the time the AsyncTask() function is run, the reference of const bool isCurrentOverlayActive doesn’t exists anymore. And that is why it was returning a false value.

If someone with more experience can confirm, that’d be neat.