Download

How to enable DetourCrowds?

Hey. I am working with C++ and not blueprints.
I have ACharacter class working with UNavigationSystem for navigating.
The problem is that the actors do not “sees” each other on the nav mesh (they are skeletal meshes).
I want them to navigate to a specific point while knowing that other skeletal meshes is on there way.
So I have look for DetourCrowds and I have found that for enabling it I need to do this:


 AMyVeryOwnAIController::AMyVeryOwnAIController(const FPostConstructInitializeProperties& PCIP)
 : Super(PCIP.SetDefaultSubobjectClass<UCrowdFollowingComponent>(TEXT("PathFollowingComponent")))
 {
     // ...
 }

https://answers.unrealengine.com/questions/73218/how-to-enable-detour-crowds-in-ue43.html
But this is a solution for UE 4.3 and not UE 4.7.
How can I enable Detour Crowds in the latest version (4.7.5)?

UP…

UP…

I believe there is a detour crowd AI controller by default now.

Which means it supose to work? Well, it isn’t.

Calm down. It means look at the class not that it should just work.

.cpp


#include "AIModulePrivate.h"
#include "DetourCrowdAIController.h"
#include "Navigation/CrowdFollowingComponent.h"

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

}

.h



#pragma once

#include "AIController.h"
#include "DetourCrowdAIController.generated.h"

UCLASS()
class ADetourCrowdAIController : public AAIController
{
	GENERATED_BODY()
public:
	ADetourCrowdAIController(const FObjectInitializer& ObjectInitializer);
};

Thank you for your answer.
Is there another way to do it? beacause my class dreived from ACharacter and I need the functions of ACharacter like GetActorLocation() and Controller.
I have tried to inheritance from both classes but it does not let me.

This is for the controller not the character. The controller tells the character what to do. Your AIController should not be a child of ACharacter. To get access to the functions of the character you would use something like this:



Cast<ACharacter>(GetControlledPawn())->getActorLocation();


Ok so I need a class which dreives from ACharacter and class which dreives from AAIController.
In that case can I create object of the ACharacter from the AAIController class?
Because I need the Actors to know about each other for another functions that I am creating.

Nope. you are looking at it wrong. There are 2 parts to a character. Mind and Body. The body is a Pawn (or child of pawn like Character) The mind is the Controller (PlayerController for players AIControllers for NPC’s). A controller’s job is to tell the Pawn what to do. The Pawns job is to physically do it. For example. The AIcontroller says follow this path to this location, The pawn physically moves/animates.

In your case you need a Character as a Body and an AIController as a Mind. They know about eachother because a controller possesses a Pawn.

If you are in the Pawn/Character You can get the controller by calling GetController.
If you are in the **Controller **you can get the Pawn by calling GetControlledPawn.

I think I got it. But one question. As you worte I need to create class which derives from AAIController. So this is my mind of the character.
Now, I need to use GetControlledPawn and set all the variable such as skeletal mesh component and capsule component to create my physical character?
Or I can create a character class and somehow connect between the character and the AAIController? Beacause as I have seen, when I write GetController I get AController type and not AAIController.
Thank you! You are very helpful

You create an AIController and a Character. Spawn both into the world and call Possess to make the AI controller and Pawn work together.

When it returns a controller you can cast it to an AIController and everything will worl. AController is just the base class for both PlayerControllers as well as AIControllers

Thank you! It works :smiley: