# this was nullptr when trying to get coordinates

**URL:** <https://forums.unrealengine.com/t/this-was-nullptr-when-trying-to-get-coordinates/2079838>\
**Category:** AI\
**Tags:** ai-navigation, Behavior-Tree, behavior-tree-task, unreal-engine, CPP, question\
**Created:** [October 22, 2024, 9:05am UTC](https://forums.unrealengine.com/t/this-was-nullptr-when-trying-to-get-coordinates/2079838 "2024-10-22T09:05:00Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![M4yh3m.exe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@M4yh3m.exe](https://forums.unrealengine.com/u/M4yh3m.exe)\
**Post date:** [October 24, 2024, 9:18am UTC](https://forums.unrealengine.com/t/this-was-nullptr-when-trying-to-get-coordinates/2079838/21 "2024-10-24T09:18:28Z")

</div>

I managed to do it, here is the code, I will still finish it, but in fact it already moves the mesh to the ceiling and the AI ​​can walk

```auto
#include "Task_GoToCeiling.h"
#include "LineTrace.h"
#include "Kismet/GameplayStatics.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BTAIController.h"
#include "ZombieEnemyCPP.h"
#include "NavigationSystem.h"
#include "DrawDebugHelpers.h"

EBTNodeResult::Type UTask_GoToCeiling::
ExecuteTask(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory)
{
	ZombieActorChar = OwnerComp.GetAIOwner()->GetCharacter();
	TSubclassOf<UActorComponent> ULineTrace;
	ActorComp = ZombieActorChar->GetRootComponent()->GetChildComponent(0);
	FVector StartCapsule = ZombieActorChar->GetCapsuleComponent()->GetComponentLocation();
	FVector EndCapsule = StartCapsule + ZombieActorChar->GetCapsuleComponent()->GetUpVector() * 400.0f;

	FHitResult HitResult;
	FCollisionObjectQueryParams CollisionParams;
	FCollisionQueryParams CollisionQueryParams;
	CollisionQueryParams.AddIgnoredActor(ZombieActorChar);

	/*ZombieActorChar->GetCapsuleComponent()->LineTraceComponent(OUT HitResult,
		StartCapsule,
		EndCapsule,
		CollisionQueryParams);*/
	ZombieActorChar->GetWorld()->LineTraceSingleByObjectType(OUT HitResult,
		StartCapsule,
		EndCapsule,
		CollisionParams,
		CollisionQueryParams);
	UE_LOG(LogTemp, Warning, TEXT("wtf"));

	DrawDebugLine(
		GetWorld(),
		StartCapsule,
		EndCapsule,
		FColor::Red,
		false,
		3.0f,
		0,
		5.0f
	);
	if (HitResult.bBlockingHit && HitResult.GetComponent()->ComponentHasTag("Ceiling"))
	{
		UE_LOG(LogTemp, Warning, TEXT("HELLO"));
		FRotator CeilingRotation = (FRotator(180.0f, -90.0f, ZombieActorChar->GetControlRotation().Yaw));
		
		ZombieActorChar->GetMesh()->K2_SetWorldLocationAndRotation(HitResult.Location, CeilingRotation, true, HitResult, true);
		/*bOnTheCeiling = true;*/
		UE_LOG(LogTemp, Warning, TEXT("HAVE CEILING"));

	}
	else
	{
		UE_LOG(LogTemp, Warning, TEXT("FAIL"));
		return EBTNodeResult::Failed;
	}
	UE_LOG(LogTemp, Warning, TEXT("Success"));
	return EBTNodeResult::Succeeded;
}

```

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 23, 2024, 9:19am UTC](https://forums.unrealengine.com/t/this-was-nullptr-when-trying-to-get-coordinates/2079838/22 "2024-11-23T09:19:26Z")

</div>

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

[Previous page](https://forums.unrealengine.com/t/this-was-nullptr-when-trying-to-get-coordinates/2079838.md?page=1)
