MoveToLocation() IsThereSomthing I Miss?

I used MoveToLocation() a few times in C++ without any problem but this time no matter what it gonna be fail.

270310-98484984.jpg

In AiControler I implement MoveToLocation() in Tick.

void ABaseAIControllerV1::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);


	MoveToLocation(FVector(0,0,0));

	UE_LOG(LogTemp, Warning, TEXT("AI =%s "),*GetPawn()->GetName());

}

and implement RequestDirectMove() in UNavMovementComponent .

void UShipMovementComponent::RequestDirectMove(const FVector & MoveVelocity, bool bForceMaxSpeed)
{

	UE_LOG(LogTemp, Warning, TEXT("RequestDirectMove"));

}

But you can see only log in AIControler reply in output.

270322-6546456.jpg

its seems MoveToLocation() fail !! but why .
there is anything I miss?
please if you don’t see anything wrong tell me too.

it must be easy but I trapped in it for a few days, please someone help.

Proof for NaveMeshVolume

Calling MoveToLocation on tick is a bit excessive. Unless if the target location changes dramatically 60 times a second you should get away with a lot less navigation queries.

Thanks for reply .
I just want it to work then I think about a more efficient way.
I don’t use any plugin, RequestDirectMove is part of UNavMovementComponent .

My mistake I overlooked it. Since you are overriding RequestDirectMove have you tried to include a call to Super::RequestDirectMove ?

it must work it without it but I tried that before and now I tried that again but sadly no change.

void UShipMovementComponent::RequestDirectMove(const FVector & MoveVelocity, bool bForceMaxSpeed)
{
	Super::RequestDirectMove(MoveVelocity, bForceMaxSpeed);

	UE_LOG(LogTemp, Warning, TEXT("RequestDirectMove"));

}

Move to Location works if you just call it once right?

I call it once but still its failed.

MoveToLocation() has a return value, right? Can you please print that out and post it here?

Thanks for Checking my Questions.
It Failed.

LogTemp: Warning: AI =BP_EnemyPawnShip_188
LogTemp: Warning: BP_EnemyPawnShip_188=Failed

Have you tried another coordinates not just FVector(0,0,0), but something that is definitely on navmesh? Just to make sure

To be sure of that I used MoveToActor();
But the result is the same.

MoveToActor(AllWayPoints[0]);

LogTemp: Warning: AI =BP_EnemyPawnShip_188
LogTemp: Warning: BP_EnemyPawnShip_188=Failed
LogTemp: Warning: WaypointLocation=X=2100.000 Y=-3280.000 Z=-150.000

im going to be crazy!

Well, I have tried to reproduce your problem. Everything works fine. I have UE4.21
Here is my code, just fill up the holes in your code

ZControllerAI.h

#pragma once

#include "CoreMinimal.h"
#include "AIController.h"
#include "ZControllerAI.generated.h"

UCLASS()
class MOVEMENTTEST_API AZControllerAI : public AAIController
{
	GENERATED_BODY()

public:

	UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
		AActor* ActorToMove;

	virtual void Tick(float DeltaSeconds) override;
};

ZControllerAI.cpp

#include "ZControllerAI.h"
#include "DrawDebugHelpers.h"

void AZControllerAI::Tick(float DeltaSeconds)
{
	if (ActorToMove != nullptr) {
		auto res = MoveToActor(ActorToMove, 10);
		//auto res = MoveToLocation(FVector(0,0,0), 10);

		auto pathComp = GetPathFollowingComponent();
		if(pathComp != nullptr) {
			auto path	= pathComp->GetPath();
			auto world	= GetWorld();
			if (path.IsValid()) {
				auto points = path->GetPathPoints();
				for (int32 pInd = 1; pInd < points.Num(); pInd++) {
					DrawDebugLine(world, points[pInd - 1].Location, points[pInd].Location, FColor::Green, false, -1, 0, 5);
				}
			}
		}
	}

}

ZMovementComponentReq.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PawnMovementComponent.h"
#include "ZMovementComponentReq.generated.h"

UCLASS()
class MOVEMENTTEST_API UZMovementComponentReq : public UPawnMovementComponent
{
	GENERATED_BODY()

	virtual void RequestDirectMove(const FVector& MoveVelocity, bool bForceMaxSpeed) override;

	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

ZMovementComponentReq.cpp

#include "ZMovementComponentReq.h"
#include "DrawDebugHelpers.h"

void UZMovementComponentReq::RequestDirectMove(const FVector & MoveVelocity, bool bForceMaxSpeed)
{
	Super::RequestDirectMove(MoveVelocity, bForceMaxSpeed);
	Velocity.Z = 0;
	Velocity = Velocity.GetClampedToMaxSize(100.0f);

	UE_LOG(LogTemp, Log, TEXT("MoveVel: %s"), *Velocity.ToString())
}

void UZMovementComponentReq::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction * ThisTickFunction)
{
	FVector deltaMove = Velocity * DeltaTime;

	if (deltaMove.IsNearlyZero()) return;

	auto rot = deltaMove.GetSafeNormal().Rotation();

	FHitResult hit;
	SafeMoveUpdatedComponent(deltaMove, rot, true, hit);

	if (hit.IsValidBlockingHit()) {
		SlideAlongSurface(deltaMove, 1.f - hit.Time, hit.Normal, hit);
	}

	UE_LOG(LogTemp, Warning, TEXT("Velocity: %s"), *deltaMove.ToString());

	auto loc = UpdatedComponent->GetComponentLocation();
	DrawDebugLine(GetWorld(), loc, loc + Velocity, FColor::Red, false, -1, 0, 5);
}

ZNavPawn.h

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "ZNavPawn.generated.h"


class UZMovementComponentReq;
class UStaticMeshComponent;
class UCapsuleComponent;

UCLASS()
class MOVEMENTTEST_API AZNavPawn : public APawn
{
	GENERATED_BODY()

public:
	// Sets default values for this pawn's properties
	AZNavPawn();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	// Called to bind functionality to input
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;


	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
		UZMovementComponentReq* ZMoveComp;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
		UStaticMeshComponent* MeshComp;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
		UCapsuleComponent* CapsuleComp;


	virtual UPawnMovementComponent* GetMovementComponent() const override;

};

ZNavPawn.cpp

#include "ZNavPawn.h"
#include "Components/CapsuleComponent.h"
#include "Components/StaticMeshComponent.h"
#include "ZMovementComponentReq.h"
#include "Engine/CollisionProfile.h"

// Sets default values
AZNavPawn::AZNavPawn()
{
 	// Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	CapsuleComp = CreateDefaultSubobject<UCapsuleComponent>("Capsule");

	RootComponent = CapsuleComp;
	CapsuleComp->InitCapsuleSize(35, 90);
	CapsuleComp->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
	CapsuleComp->CanCharacterStepUpOn = ECB_No;
	CapsuleComp->SetShouldUpdatePhysicsVolume(true);
	CapsuleComp->bCheckAsyncSceneOnMove = false;
	CapsuleComp->SetCanEverAffectNavigation(false);
	CapsuleComp->bDynamicObstacle = true;


	MeshComp = CreateDefaultSubobject<UStaticMeshComponent>("Mesh");
	MeshComp->SetupAttachment(CapsuleComp);
	MeshComp->SetCanEverAffectNavigation(false);

	ZMoveComp = CreateDefaultSubobject<UZMovementComponentReq>("MovementComp");
	ZMoveComp->UpdatedComponent = CapsuleComp;
}

// Called when the game starts or when spawned
void AZNavPawn::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AZNavPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void AZNavPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

}

UPawnMovementComponent * AZNavPawn::GetMovementComponent() const
{
	return ZMoveComp;
}

It looks like under your pawns, there is no nav mesh generated. Do they maybe prevent the nav mesh to be generated right beneath them and are therefore not on the nav mesh?

Hi, thanks for the reply. I learn a lot of from your code, my main problem was I had Can ever affect navigation to true and acceptance radius must have + plus value but if it had value lower 0 its gonna be fail.
Alazar I run your code perfectly first time but the second time it runs its failed, can you tell me why? ( I didn’t change anything )

Oops, sorry, I forgot to mention ActorToMove in ZControllerAI.h if its null then nothing would work. So, you should set it or remove this check and use MoveToLocation instead. In your pawn (MyZNavPawn) add a variable reference to actor, make it public and set it in editor, like on picture

it’s really awesome every time I see I total stranger put a lot of time to respawn to my question,
I learn a lot of your code and thanks to you I finish my AI movement and it forced to use player movement.
if possible can you give me some info about SlideAlongSurface :

if it’s not too much to ask can you check this question too?

thanks.