Why my second AICharacter just do once AroundTask?

Hi~My first AICharacter is always do AroundTask,but my second AICharacter just do once and stop…

Hey Mr.Zippo,

Your code looks good, but the reason why your second AI does not work is because the FinishLatentTask() never gets called on him!

You save the NodeOwnerComp as a variable in the node’s class but the behaviour task’s do not work like that. This has something to do how they are stored in memory…
Basically what you do when the second AI calls OnMoveCompleted() you call the FinishLatentTask() on the first AI.

The way to fix it is to store your NodeOwnerComp in the NodeMemory and then later get it out of there.

You will need to do something like this:

In the .h:

struct FBTCustomTaskMemory
{
 class UBehaviourTreeComponent NodeOwnerComp;
};

class Game_API UCustomBTTask
{
 virtual uint16 GetInstanceMemorySize() const override
 { 
  return sizeof(FBTCustomTaskMemory);
 }
};

And then in the .cpp you can save the nodeOwnerComp:

FBTCustomTaskMemory* myMemory = (FBTCustomTaskMemory*)NodeMemory;
myMemory->NodeOwnerComp = NodeOwnerComp;

To get it out of memory you call:

FBTCustomTaskMemory* myMemory = (FBTCustomTaskMemory*)NodeMemory;
FinishLatentTask(myMemory->NodeOwnerComp,...)

Hope this helps, good luck :slight_smile:
Elias