ExecuteTask return value

I was wondering, the Super::ExecuteTask would return a value as well, but in our version we ignore that value. It probably isn’t relevant in this specific case, but how is this supposed to be handled in a more generic case?

For reference, I added this to my implementation:

	if (result == EBTNodeResult::Type::Aborted || result == EBTNodeResult::Type::Failed)
		return result;
	else
		return EBTNodeResult::Type::Succeeded;

Does that make sense at all?

Well I’m lacking context as I haven’t watched these lectures but by the sounds of it, just store it in a variable?

bool bSuccess = Super::ExecuteTask(/*...*/);
// code...
return bSuccess;

Yeah that is basically what I did (store the result of the Super call in a variable). The questions was probably not very well formulated, so let me try again: I was wondering if, when the super class returns failure, would we still “do our thing”, or immediately return? Does the super class’ result take precedence?

As I said, obviously this is a very simple case but I wonder how that should be generally handled.

For reference, here’s the entire function:

EBTNodeResult::Type UBTTask_ClearBlackboardValue::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	EBTNodeResult::Type result = Super::ExecuteTask(OwnerComp, NodeMemory); 

	OwnerComp.GetBlackboardComponent()->ClearValue(GetSelectedBlackboardKey());

	if (result == EBTNodeResult::Type::Aborted || result == EBTNodeResult::Type::Failed)
		return result;
	else
		return EBTNodeResult::Type::Succeeded;
}

If the super function fails it seems correct to also fail. I would code that slightly different to how you did however.

EBTNodeResult::Type UBTTask_ClearBlackboardValue::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	EBTNodeResult::Type Result = Super::ExecuteTask(OwnerComp, NodeMemory);
    if (Result == EBTNodeResult::Type::Succeeded)
    {
	    OwnerComp.GetBlackboardComponent()->ClearValue(GetSelectedBlackboardKey());
		return EBTNodeResult::Type::Succeeded;
    }
    return Result;
}
``

That’s what I suspected, just wasn’t sure what the “recommended” practice is.
Thanks for the reply :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms