# Uncorrect working BehaviourTree & Node with multiple characters

**URL:** <https://forums.unrealengine.com/t/uncorrect-working-behaviourtree-node-with-multiple-characters/2049729>\
**Category:** AI\
**Tags:** Behavior-Tree, bttask, unreal-engine, question\
**Created:** [October 2, 2024, 1:32pm UTC](https://forums.unrealengine.com/t/uncorrect-working-behaviourtree-node-with-multiple-characters/2049729 "2024-10-02T13:32:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dmitry\_31k](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Dmitry\_31k](https://forums.unrealengine.com/u/Dmitry_31k)\
**Post date:** [October 2, 2024, 1:32pm UTC](https://forums.unrealengine.com/t/uncorrect-working-behaviourtree-node-with-multiple-characters/2049729/1 "2024-10-02T13:32:20Z")

</div>

I wrote a `BTTaskNode` that worked correctly with one character in my scene. However, after I added another character of the same class to my scene, everything broke. One character just stands still and does nothing, while the other character goes in a different direction than I indicated. I tried logging the start and target character positions, and they are calculated correctly. After that, I tried to rewrite my node, and instead of moving, it simply teleported by using `SetActorLocation`. However, after this, both of my characters teleported to the same place and much further than I indicated. I tried asking ChatGPT and searching for a solution in forums, but I couldn’t find a case similar to mine.  
Original code:

// Fill out your copyright notice in the Description page of Project Settings.

#include “BTTask\_MoveToWithoutRotation.h”  
#include “Math/UnrealMathUtility.h”  
#include “BehaviorTree/BlackboardComponent.h”  
#include “AIController.h”

UBTTask\_MoveToWithoutRotation::UBTTask\_MoveToWithoutRotation()  
{  
NodeName = “Move to target without changing rotation”;  
bNotifyTick = true;  
}

EBTNodeResult::Type UBTTask\_MoveToWithoutRotation::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8\* NodeMemory)  
{  
Super::ExecuteTask(OwnerComp, NodeMemory);

```
OwnerAIController = OwnerComp.GetAIOwner();
OwnerPawn = OwnerAIController->GetPawn();

if (OwnerPawn == nullptr || OwnerAIController == nullptr)
{
    return EBTNodeResult::Failed;
}

return EBTNodeResult::InProgress;

```

}

void UBTTask\_MoveToWithoutRotation::TickTask(UBehaviorTreeComponent& OwnerComp, uint8\* NodeMemory, float DeltaSeconds)  
{  
Super::TickTask(OwnerComp, NodeMemory, DeltaSeconds);

```
FVector CurrentLocation = OwnerPawn->GetActorLocation();
FVector TargetLocation = OwnerComp.GetBlackboardComponent()->GetValueAsVector(GetSelectedBlackboardKey());

FVector ToSetLocation = FMath::VInterpConstantTo(CurrentLocation, 
    TargetLocation,
    DeltaSeconds,
    MovingSpeed
);

if (FVector::Dist(CurrentLocation, TargetLocation) <= 1)
{
    FinishLatentTask(OwnerComp, EBTNodeResult::Succeeded);
}

OwnerPawn->SetActorLocation(ToSetLocation);

```

}
