# BP latent / async nodes from a class and triggered by delegate

**URL:** <https://forums.unrealengine.com/t/bp-latent-async-nodes-from-a-class-and-triggered-by-delegate/1116128>\
**Category:** Programming & Scripting\
**Tags:** async, Execution-Flow, unreal-engine, nodes, CPP, Blueprint, question\
**Created:** [April 18, 2023, 6:26pm UTC](https://forums.unrealengine.com/t/bp-latent-async-nodes-from-a-class-and-triggered-by-delegate/1116128 "2023-04-18T18:26:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![II\_ADN\_II](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ii_adn_ii/32/1194656_2.png) [@II\_ADN\_II](https://forums.unrealengine.com/u/II_ADN_II)\
**Post date:** [April 18, 2023, 6:26pm UTC](https://forums.unrealengine.com/t/bp-latent-async-nodes-from-a-class-and-triggered-by-delegate/1116128/1 "2023-04-18T18:26:17Z")

</div>

Hi, I have been messing around with UBlueprintAsyncActionBase and FPendingLatentAction to control the flow execution in BP. Essentially I the node triggers an _action_ and the execution should continue once the action is done.  
I use a delegate to know when the action has ended and got it working with UBlueprintAsyncActionBase. The problem is that the node is available from any class, I wan it to be used like a regular function, ONLY on this class.

On the other hand with FPendingLatentAction I get the class only behavior just by adding the latent action in the class function. But I cannot seem able to bind the end with the delegate. I need it to work with the delegate as I need it to return the _action_ state.

FPendingLatentAction .h

```auto

		UFUNCTION(BlueprintCallable, Category = "BP", meta = (Latent, LatentInfo = "LatentInfo", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
			virtual void GetRequest(UObject* WorldContextObject, struct FLatentActionInfo LatentInfo);

```

FPendingLatentAction .cpp

```auto
void UUnitBehavior::GetRequest(UObject* WorldContextObject, FLatentActionInfo LatentInfo)
{
	// Prepare latent action
	if (UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject) )
	{
		FLatentActionManager& LatentActionManager = World->GetLatentActionManager();
		if (LatentActionManager.FindExistingAction<FDelayAction>(LatentInfo.CallbackTarget, LatentInfo.UUID) == NULL)
		{
			LatentActionManager.AddNewAction(LatentInfo.CallbackTarget, LatentInfo.UUID, new FDelayAction( 5.0f, LatentInfo));
				
		}
	}
}

```

---

<div class="post-metadata">

**Author:** ![II\_ADN\_II](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ii_adn_ii/32/1194656_2.png) [@II\_ADN\_II](https://forums.unrealengine.com/u/II_ADN_II)\
**Post date:** [April 20, 2023, 6:51pm UTC](https://forums.unrealengine.com/t/bp-latent-async-nodes-from-a-class-and-triggered-by-delegate/1116128/2 "2023-04-20T18:51:59Z")

</div>

Found the problem. For non UObjects like FPendingLatentAction you need to bind with BindRaw to a nonDynamic delegate. Just save the E

LatentAction .h

```auto
FDelegateHandle EndHandler;

```

LatentAction .cpp

```auto
EndHandler = yourObject->OnFinishedTaskDelegate.AddRaw(this, &FYourLatentAction::End);

```

And the delegate you want to bind, in this case multicast one param

classToBind.h

```auto
DECLARE_MULTICAST_DELEGATE_OneParam(FOnFinishedTask, const bool);

```

PD: Also make sure you dont name your latent action like FDelayAction or some engine existing class. Got my Delay nodes not working ONLY on the build without a single error anywhere 😮‍💨
