I want to get location of a ATargetPoint Actor in C++. The target point is set it from BP
I know the ATargetPoint extend in AActor, it is strange that why I cannot use the GetActorLocation.
My Header is
UCLASS()
class ASTEROIDGAME_API ABoundaries : public AActor
{
GENERATED_BODY()
public:
UPROPERTY(Category = Mesh, VisibleDefaultsOnly, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* PlaneMesh;
UPROPERTY(VisibleDefaultsOnly, Category = Collision)
class UBoxComponent* CollisionComponent;
UPROPERTY(EditAnywhere, Category = "Spawn Location")
TSubclassOf<ATargetPoint> TargetPoint;
// Sets default values for this actor's properties
ABoundaries();
UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
and the cpp is
// Fill out your copyright notice in the Description page of Project Settings.
#include "Boundaries.h"
#include "SpaceCraftPawn.h"
#include "Engine/World.h"
// Sets default values
ABoundaries::ABoundaries()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
PlaneMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BaseMesh"));
RootComponent = PlaneMesh;
CollisionComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("Collision"));
CollisionComponent->AttachTo(RootComponent);
CollisionComponent->OnComponentBeginOverlap.AddDynamic(this, &ABoundaries::OnOverlapBegin);
}
// Called when the game starts or when spawned
void ABoundaries::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABoundaries::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void ABoundaries::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if ((OtherActor != NULL) && (OtherActor != this) && (OtherComp != NULL))
{
ASpaceCraftPawn* SpaceCraftPawn = Cast<ASpaceCraftPawn>(OtherActor);
if (SpaceCraftPawn)
{
UWorld* World = GetWorld();
if (World)
{
FActorSpawnParameters SpawnParams;
SpawnParams.Owner = this;
SpawnParams.Instigator = Instigator;
World->SpawnActor<ABoundaries>(GetClass(), FVector(100,0,0), FRotator::ZeroRotator, SpawnParams);
}
UE_LOG(LogTemp, Warning, TEXT("OverLap Begin"));
}
}
}