this was nullptr when trying to get coordinates

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

#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;
}
1 Like