SimpleMoveToLocation does not work with AIController

Hey, I have created 2 classes. One which derives from AIController and one which derives from ACharacter.
On the AIController I spawn the ACharacter in the BeginPlay function and posses it to the controller:

void AVikingController::BeginPlay()
{
	Super::BeginPlay();

	AViking* vi = GetWorld()->SpawnActor<AViking>(vikingBp, FVector(750, 1000, 200), FRotator::ZeroRotator);
	Possess(vi);
}

On the ACharacter Class I have:

NavSys->SimpleMoveToLocation(Cast<AAIController>(GetController()), hit.ImpactPoint);

I have nav mesh on the editor and weird think happens.
I set a target position which the character suppose to get there by SimpleMoveToLocation and where it interacts with the cube the character stops moving:

https://forums.unrealengine.com/attachment.php?attachmentid=35598&d=1429460856

https://forums.unrealengine.com/attachment.php?attachmentid=35599&d=1429461115

Moreover, when I change the AIController to AController it works fine! (and the casting too of curse).
So the problem is in the AIController, why?

Umm I can change that.
Anyway I creates it from the player controller class:

 void AVikingKingPlayerController::BeginPlay()
    {
    	Super::BeginPlay();
    
    
    	//Spawn actors when game launches (temp)
    	GetWorld()->SpawnActor<AVikingController>(AVikingController::StaticClass(), FVector(), FRotator::ZeroRotator);
    }

Is it bug of UE4?

Well, It changed it all. Now the ACharacter creates the controller and the character spawns from the playercontroller (with FVector(x,y,z)).
On the constructor of the character I have added this:

AIControllerClass = AVikingController::StaticClass();
AutoPossessPlayer = EAutoReceiveInput::Disabled;

But it does not create a controller right?
How can I create a controller and set it to the character?

EDIT: I have added this on the BeginPlay function and now the character has an aicontroller:

SpawnDefaultController();

But the bug is still exist.

How do you spawn the AI controllers? I’m asking because what you described is in opposite to what we usually do. Usually you create a Character class and set its AIControllerClass to your AI controller class, and then just spawn characters and the controller gets spawned automatically.

Would you mind sharing some more information in this regard?

Cheers,

–mieszko

I’m not sure - I’ve never seen anyone doing it this way :slight_smile:

However, since you’re using C++, I suggest checking what FVector() really does. You basically create an AIController in an unidentified “somewhere”.

Please try spawning characters first and rely on internal UE4 mechanics to spawn AI controllers for them.

Also, make sure your characters’ AutoPossessPlayer is set to Disabled - otherwise the way you set up things will result in a pawn auto-possessed by player controller.

By default only manually-placed characters get default controller to spawn. But you can change that by setting Pawn.AutoPossessAI to PlacedInWorldOrSpawned. Or you can manually call SpawnDefaultController on your characters after spawning.

Ok, I have added on the constructor:

AutoPossessAI = EAutoPossessAI::PlacedInWorldOrSpawned;

But the bug is still exist.

Have you tried debugging it in any way? Putting breakpoints, validating parameters, looking at return values. Have you tried looking at it with Log Visualizer? If not I highly encourage you to do so, and regarding Log Visualizer, there should be enough info on the internet (especially this site and the forum) to get you going.

Ok I have checked some stuff and apparently on the constructor on the AIController (CPP side) I have this:

AVikingController::AVikingController(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))

I have needed the character to know about each other because I had the SimpleMoveToLocation function and I have wanted the characters not to collision each other but to pass each other. So I have added this.
When I changes it to that:

AVikingController::AVikingController(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.Get())

It works fine but the character do not know about each other.
How can I fix it?

Well, you can use RVO, which you enable with bUseRVOAvoidance flag you your AI’s character movement component. Mind however that RVO doesn’t care about navmesh, so you may run into issues if AI staying o navmesh is important to you.

Having staid that, it should all work with UCrowdFollowingComponent you had set up before. Would you mind supplying us with a stripped-down version of your project so that we can investigate the issue? Feel free to send it o me at mieszko.zielinski@epicgames.com.

Thank you so much for your help!
I have just sent you the project on email.Please let me know if you got it.

Found it. You’ve used SimpleMoveToLocation which apparently does not work with CrowdFollowingComponent (which is a bug of course and I’ve just filed it as a such). It all works fine if you use AAIController::MoveToLocation instead.

Actually it is not. Now the bug is not exist any more but when I try to move the character in a path which blocked by another character it acting weird.
In addition the character always looks at the target and not in the direction of his path. Is there a way to fix it? And when will Epic fix the bug?

Sounds like a totally different issue that should be tracked separately.