void FLatentActionManager::TickLatentActionForObject(float DeltaTime, FActionList& ObjectActionList, UObject* InObject)
{
    typedef TPair<int32, FPendingLatentAction*> FActionListPair;
    TArray<FActionListPair, TInlineAllocator<4>> ItemsToRemove;

    FLatentResponse Response(DeltaTime);
    for (TMultiMap<int32, FPendingLatentAction*>::TConstIterator It(ObjectActionList); It; ++It)
    {
        FPendingLatentAction* Action = It.Value();

        Response.bRemoveAction = false;

        Action->UpdateOperation(Response);

        if (Response.bRemoveAction)
        {
            new (ItemsToRemove) FActionListPair(TPairInitializer<int32, FPendingLatentAction*>(It.Key(), Action));
        }
    }

    // Remove any items that were deleted
    for (int32 i = 0; i < ItemsToRemove.Num(); ++i)
    {
        const FActionListPair& ItemPair = ItemsToRemove[i];
        const int32 ItemIndex = ItemPair.Key;
        FPendingLatentAction* DyingAction = ItemPair.Value;
        ObjectActionList.Remove(ItemIndex, DyingAction);
        delete DyingAction;
    }

    // Trigger any pending execution links
    for (int32 i = 0; i < Response.LinksToExecute.Num(); ++i)
    {
        FLatentResponse::FExecutionInfo& LinkInfo = Response.LinksToExecute[i];
        if (LinkInfo.LinkID != INDEX_NONE)
        {
            if (UObject* CallbackTarget = LinkInfo.CallbackTarget.Get())
            {
                check(CallbackTarget == InObject);

                if (UFunction* ExecutionFunction = CallbackTarget->FindFunction(LinkInfo.ExecutionFunction))
                {
                    CallbackTarget->ProcessEvent(ExecutionFunction, &(LinkInfo.LinkID));
                }
                else
                {
                    UE_LOG(LogScript, Warning, TEXT("FLatentActionManager::ProcessLatentActions: Could not find latent action resume point named '%s' on '%s' called by '%s'"),
                           *LinkInfo.ExecutionFunction.ToString(), *(CallbackTarget->GetPathName()), *(InObject->GetPathName()));
                }
            }
            else
            {
                UE_LOG(LogScript, Warning, TEXT("FLatentActionManager::ProcessLatentActions: CallbackTarget is None."));
            }
        }
    }
}
예제 #2
0
//------------------------------------------------------------------------------
void FBlueprintActionDatabase::ClearUnloadedAssetActions(FName ObjectPath)
{
	// Check if the asset can be found in the unloaded action registry, if it can, we need to remove it
	if(TArray<UBlueprintNodeSpawner*>* UnloadedActionList = UnloadedActionRegistry.Find(ObjectPath))
	{
		for(UBlueprintNodeSpawner* NodeSpawner : *UnloadedActionList)
		{
			FActionList* ActionList = ActionRegistry.Find(NodeSpawner->NodeClass);

			// Remove the NodeSpawner from the main registry, it will be replaced with the loaded version of the action
			ActionList->Remove(NodeSpawner);
		}

		// Remove the asset's path from the unloaded registry, it is no longer needed
		UnloadedActionRegistry.Remove(ObjectPath);
	}
}