# How to make AI look at an object?

**URL:** <https://forums.unrealengine.com/t/how-to-make-ai-look-at-an-object/450111>\
**Category:** C++\
**Tags:** aiperception, ai-controller, unreal-engine, UE4, question, CPP\
**Created:** [June 4, 2019, 9:15am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-at-an-object/450111 "2019-06-04T09:15:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xTC\_Envy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@xTC\_Envy](https://forums.unrealengine.com/u/xTC_Envy)\
**Post date:** [June 4, 2019, 9:15am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-at-an-object/450111/1 "2019-06-04T09:15:23Z")

</div>

Hi all. I want to make a task for a Pawn which has its own and custom AIController to look at an specific object in the world (an actor). What I’ve tried so far is to create a task with an AActor UPROPERTY which will be the object I want the AI to look at, and then in the “ExecuteTask” function I get the rotator with “Find look at rotation” between the pawn and the aactor. Finally, I just set the pawn rotation.

```
EBTNodeResult::Type UTK_TaskLookAtObject::ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	ATK_AIController *AIController = Cast<ATK_AIController>(OwnerComp.GetAIOwner());
	if (AIController)
	{
		UBlackboardComponent* BlackboardComp = AIController->GetBlackboardComponent();
		AActor* Enemy = AIController->GetPawn();
		if (Enemy && ObjectToLookAt)
		{
			FVector TargetLocation(ObjectToLookAt->GetActorLocation().X, ObjectToLookAt->GetActorLocation().Y, Enemy->GetActorLocation().Z);
			FRotator EnemyRotation = UKismetMathLibrary::FindLookAtRotation(Enemy->GetActorLocation(), TargetLocation);
			Enemy->SetActorRotation(EnemyRotation);
			BlackboardComp->SetValueAsObject(AIController->Target, ObjectToLookAt);
			return EBTNodeResult::Succeeded;
		}
	}
	return EBTNodeResult::Failed;
}

```

The problem is that I can’t select the actor in the task properties in the editor, and I think it is because it is not possible to choose a scene actor directly because the default properties of the task are not tied to any world.

I can’t think about another way of doing this, so please can anybody help me? Thank you very much in advance!

---

<div class="post-metadata">

**Author:** ![Natalo77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natalo77](https://forums.unrealengine.com/u/Natalo77)\
**Post date:** [February 18, 2022, 10:53am UTC](https://forums.unrealengine.com/t/how-to-make-ai-look-at-an-object/450111/2 "2022-02-18T10:53:32Z")

</div>

I think the correct way to do this will be setting an `ObjectToLookAt` on your `Blackboard`, then accessing that in this `Task`
