Hello everyove i have strange problem but I do not understand what is wrong. I want be char move to player
aicontroller class
#include "MyProject.h"
#include "MyAIController.h"
#include "AssentilalChar.h"
AMyAIController::AMyAIController(const class FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
BehaviorComp = ObjectInitializer.CreateDefaultSubobject<UBehaviorTreeComponent>(this, TEXT("BehaviorComp"));
BlackboardComp = ObjectInitializer.CreateDefaultSubobject<UBlackboardComponent>(this, TEXT("BlackboardComp"));
}
void AMyAIController::Possess(class APawn* InPawn)
{
Super::Possess(InPawn);
AAssentilalChar* MyChar = Cast<AAssentilalChar>(InPawn);
BlackboardComp->InitializeBlackboard(*MyChar->BehaviorTree->BlackboardAsset);
BehaviorComp->StartTree(*MyChar->BehaviorTree);
TArray<AActor*> ActorsArray;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AAssentilalChar::StaticClass(), ActorsArray);
AAssentilalChar* player = Cast<AAssentilalChar>(ActorsArray[0]);
BlackboardComp->SetValueAsObject("Target", MyChar);
}][1]
Char Class:
#include "MyProject.h"
#include "Engine.h"
#include "MyProjectProjectile.h"
#include "MyProjectCharacter.h"
#include "AssentilalChar.h"
// Sets default values
AAssentilalChar::AAssentilalChar()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("sphere"));
RootComponent = SphereComponent;
SphereComponent->InitSphereRadius(40.0f);
SphereComponent->SetCollisionProfileName(TEXT("Pawn"));
UStaticMeshComponent* SphereVisual = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("VisualRepresentation"));
SphereVisual->SetupAttachment(RootComponent);
static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
if (SphereVisualAsset.Succeeded())
{
SphereVisual->SetStaticMesh(SphereVisualAsset.Object);
SphereVisual->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
SphereVisual->SetWorldScale3D(FVector(0.8f));
}
}
// Called when the game starts or when spawned
void AAssentilalChar::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AAssentilalChar::Tick( float DeltaTime )
{
Aitest = Cast<AAIController>(GetController());
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("This is an on screen message!"));
TArray<AActor*> SpawnedBullet;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyProjectCharacter::StaticClass(), SpawnedBullet);
EPathFollowingRequestResult::Type MoveToActorResult = Aitest->MoveToActor(SpawnedBullet[0]);
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AAssentilalChar::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
}
I create BP from cpp class and add my aicontroller and my behavior tree but my char DONT move!!! whats wrong?