Hello!
I have a problem with moving my AI character using behavior tree. The controller and character are created using c++ and behaviortree, blackboard logic via the UE4 editor. I’ve followed this tutorial to make my character jump, but after changing the default pathfollowingcomponent with new one using FObjectInitalizer, my character won’t move at all. Here’s my setup:
AIController
AMiniBossAIController::AMiniBossAIController(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer.SetDefaultSubobjectClass<UJumpPathFollowingComponent>(TEXT("PathFollowingComponent")))
When I change it to Super(ObjectInitializer), it works, but it won’t jump, cause I am not using my newly created pathfollowing component.
JumpPathFollowingComponent.h
UCLASS()
class GAME_API UJumpPathFollowingComponent : public UPathFollowingComponent
{
GENERATED_BODY()
UJumpPathFollowingComponent(const FObjectInitializer& ObjectInitializer);
protected:
/** cached UCharacterMovementComponent */
UPROPERTY(transient)
class UCharacterMovementComponent* CharacterMoveComp;
public:
// used to detect properties of a path's segment a character is about to follow
virtual void SetMoveSegment(int32 SegmentStartIndex) override;
// used to cache UCharacterMovementComponent we're using in SetMoveSegment implementation
virtual void SetMovementComponent(UNavMovementComponent* MoveComp) override;
};
**JumpPathFollowingComponent.cpp**
UJumpPathFollowingComponent::UJumpPathFollowingComponent(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
Initialize();
}
//Never fires
void UJumpPathFollowingComponent::SetMoveSegment(int32 SegmentStartIndex)
{
Super::SetMoveSegment(SegmentStartIndex);
if (CharacterMoveComp != NULL)
{
const FNavPathPoint& SegmentStart = Path->GetPathPoints()[MoveSegmentStartIndex];
if (FNavAreaHelper::HasJumpFlag(SegmentStart))
{
// jump! well... fly-in-straight-line!
CharacterMoveComp->SetMovementMode(MOVE_Flying);
}
else
{
// regular move
CharacterMoveComp->SetMovementMode(MOVE_Walking);
}
}
}
void UJumpPathFollowingComponent::SetMovementComponent(UNavMovementComponent * MoveComp)
{
}
Character moves when I use the default pathfollowingcomponent, but whenever I change it, it doesn’t find the path to the target (doesn’t matter what’s the location of the target). I’m not familiar, what’s the cause of this problem.
Waiting for your response.
With regards.