This is Exactly what I got from the errors, including a bunch of questionmarks.
C:\Users\Park\Documents\Unreal Projects\F15Test 5.1\Intermediate\Build\Win64\UnrealEditor\Inc\F15Test\UHT\PlayerC.gen.cpp(84): error C2511: ‘void APlayerC::FindTarget(const TArray<AActor *,FDefaultAllocator> &)’: ??? ?? ???‘APlayerC’?? ???ϴ?
C:\Users\Park\Documents\Unreal Projects\F15Test 5.1\Source\F15Test\Public\PlayerC.h(15): note: ‘APlayerC’ ??? ???ʽÿ?
C:\Users\Park\Documents\Unreal Projects\F15Test 5.1\Intermediate\Build\Win64\UnrealEditor\Inc\F15Test\UHT\PlayerC.gen.cpp(88): error C2352: ‘UObject::FindFunctionChecked’: ??? ?? ???ȣ???ü?? ???մϴ?
C:\Program Files\Epic Games\UE_5.1\Engine\Source\Runtime\CoreUObject\Public\UObject\Object.h(1198): note: ‘UObject::FindFunctionChecked’ ??? ???ʽÿ?
[3/3] Compile PlayerC.cpp
C:\Users\Park\Documents\Unreal Projects\F15Test 5.1\Source\F15Test\Private\PlayerC.cpp(121) : error C4717: ‘APlayerC::quicksort’: ?? ??? ???Դϴ? ??? ?? ??Ÿ? ??? ???÷ΰ? ??մϴ?
Build failed.
I have no idea what happened. Visual Studio didn’t show any error underlines.
I upload my c++ and blueprint codes hoping for some help.
This is my Player header file. It is a fighter jet.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "CInterfaceActorManager.h"
#include "CInterfaceShowWidget.h"
#include "PlayerC.generated.h"
UCLASS()
class F15TEST_API APlayerC : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APlayerC();
//Used for ManageActorsInRange
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="ManageActors")
TArray<AActor*> AllAirActors;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AllGndActors;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AllAirAllyActors;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AllGndAllyActors;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AllMissileActors;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AirActorInRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> GndActorInRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AirAllyInRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> GndAllyInRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> MissilesInRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> AirActorInCloseRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
TArray<AActor*> GndActorInCloseRange;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
int32 AirOrGround=0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "ManageActors")
AActor* CurrentTarget;
//Used for UpdatePosition
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float GravitySpeedGained;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float ThrustMultiplier;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float ThrustSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float CurrentSpeed;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Position")
float AppliedGravity=0.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Position")
FVector NewPosition;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Position")
float Drag = 0.25f;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Position")
float MinThrustNotToStall=3000.0f;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Position")
float Gravity = 981.0f;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
protected:
UFUNCTION(BlueprintCallable)
void CManageActorsInRange();
UFUNCTION(BlueprintCallable)
void CUpdatePosition();
UFUNCTION(BlueprintCallable)
void AddActorToArray(TArray<AActor*> ActorInRange, AActor* OtherActor);
UFUNCTION(BlueprintCallable)
void SortActorsByDistance(TArray<AActor*> Actors);
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void FindTarget(TArray<AActor*> ActorsInRange);
UFUNCTION()
void swap(AActor* a, AActor* b);
UFUNCTION()
int32 partition(TArray<AActor*> Actors, int32 low, int32 high);
UFUNCTION()
void quicksort(TArray<AActor*> Actors, int32 low, int32 high);
};
This is my Player cpp file
// Fill out your copyright notice in the Description page of Project Settings.
#include "PlayerC.h"
#include "Kismet/KismetMathLibrary.h"
#include "Kismet/KismetArrayLibrary.h"
#include "Kismet/KismetSystemLibrary.h"
// Sets default values
APlayerC::APlayerC()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void APlayerC::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APlayerC::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APlayerC::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
void APlayerC::CManageActorsInRange()
{
for (AActor* CurrentLoop : AllAirActors) {
if (AActor::GetHorizontalDistanceTo(CurrentLoop) < 200000.0f) {
if (!AirActorInRange.Contains(CurrentLoop))
{
AddActorToArray(AirActorInRange, CurrentLoop);
if(GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorInRange(GetOwner(),CurrentLoop);
switch (AirOrGround)
{
case 0:
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowWhite(CurrentLoop);
default:
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowX(CurrentLoop);
break;
}
}
}
else
{
if (AirActorInRange.Contains(CurrentLoop))
{
AirActorInRange.Remove(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_DisableAll(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorEscaped(GetOwner(), CurrentLoop, true, false, false);
}
else
{
if (CurrentLoop == CurrentTarget)
FindTarget(AirActorInRange);
}
}
}
for (AActor* CurrentLoop : AllGndActors) {
if (AActor::GetHorizontalDistanceTo(CurrentLoop) < 200000.0f) {
if (!GndActorInRange.Contains(CurrentLoop))
{
AddActorToArray(GndActorInRange, CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorInRange(GetOwner(), CurrentLoop);
switch (AirOrGround)
{
case 0:
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowX(CurrentLoop);
default:
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowWhite(CurrentLoop);
break;
}
}
}
else
{
if (GndActorInRange.Contains(CurrentLoop))
{
GndActorInRange.Remove(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_DisableAll(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorEscaped(GetOwner(), CurrentLoop, false, false, false);
}
else
{
if (CurrentLoop == CurrentTarget)
FindTarget(GndActorInRange);
}
}
}
for (AActor* CurrentLoop : AllAirAllyActors) {
if (AActor::GetHorizontalDistanceTo(CurrentLoop) < 200000.0f) {
if (!AirAllyInRange.Contains(CurrentLoop))
{
AddActorToArray(AirAllyInRange, CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorInRange(GetOwner(), CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowBlue(CurrentLoop);
}
}
else
{
if (AirAllyInRange.Contains(CurrentLoop))
{
AirAllyInRange.Remove(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_DisableAll(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorEscaped(GetOwner(), CurrentLoop, true, true, false);
}
}
}
for (AActor* CurrentLoop : AllGndAllyActors) {
if (AActor::GetHorizontalDistanceTo(CurrentLoop) < 200000.0f) {
if (!GndAllyInRange.Contains(CurrentLoop))
{
AddActorToArray(GndAllyInRange, CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorInRange(GetOwner(), CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_ShowBlue(CurrentLoop);
}
}
else
{
if (GndAllyInRange.Contains(CurrentLoop))
{
GndAllyInRange.Remove(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceShowWidget::StaticClass()))
ICInterfaceShowWidget::Execute_DisableAll(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorEscaped(GetOwner(), CurrentLoop, false, true, false);
}
}
}
for (AActor* CurrentLoop : AllMissileActors) {
if (AActor::GetHorizontalDistanceTo(CurrentLoop) < 200000.0f) {
if (!MissilesInRange.Contains(CurrentLoop))
{
AddActorToArray(GndAllyInRange, CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorInRange(GetOwner(), CurrentLoop);
}
}
else
{
if (MissilesInRange.Contains(CurrentLoop))
{
MissilesInRange.Remove(CurrentLoop);
AllMissileActors.Remove(CurrentLoop);
if (GetOwner()->GetClass()->ImplementsInterface(UCInterfaceActorManager::StaticClass()))
ICInterfaceActorManager::Execute_ActorEscaped(GetOwner(), CurrentLoop, false, false, true);
}
}
}
}
void APlayerC::CUpdatePosition()
{
CurrentSpeed = UKismetMathLibrary::SelectFloat(UKismetMathLibrary::FInterpTo(CurrentSpeed, ThrustSpeed, GetWorld()->DeltaTimeSeconds, Drag), ThrustSpeed, (ThrustSpeed < CurrentSpeed));
AppliedGravity = UKismetMathLibrary::MapRangeClamped(CurrentSpeed, 0.0f, MinThrustNotToStall, Gravity, 0.0f);
NewPosition = GetActorForwardVector() * CurrentSpeed * GetWorld()->DeltaTimeSeconds;
AddActorWorldOffset(UKismetMathLibrary::MakeVector(NewPosition.X, NewPosition.Y, NewPosition.Z-(AppliedGravity* GetWorld()->DeltaTimeSeconds)), true);
//How about adding another branch and subtracting Y rotation when stalling?
}
void APlayerC::AddActorToArray(TArray<AActor*> ActorInRange, AActor* OtherActor)
{
ActorInRange.Add(OtherActor);
if(!UKismetSystemLibrary::IsValid(CurrentTarget)&&((CurrentTarget->ActorHasTag("AIR")&&AirOrGround==0)||(CurrentTarget->ActorHasTag("GND")&&AirOrGround==1)))
FindTarget(ActorInRange);
}
/*void APlayerC::FindTarget(TArray<AActor*> ActorsInRange)
{
}
*/
void APlayerC::SortActorsByDistance(TArray<AActor*> Actors)
{
quicksort(Actors, 0, Actors.Num() - 1);
}
void APlayerC::swap(AActor* a, AActor* b)
{
AActor* temp = a;
a = b;
b = temp;
}
int32 APlayerC::partition(TArray<AActor*> Actors, int32 low, int32 high)
{
AActor* pivot = Actors[high];
int32 temp = low - 1;
for (int32 i = low; i < high; i++)
{
if (AActor::GetDistanceTo(Actors[i]) <= AActor::GetDistanceTo(pivot))
{
temp++;
swap(Actors[temp], Actors[i]);
}
}
swap(Actors[temp + 1], Actors[high]);
return (temp+1);
}
void APlayerC::quicksort(TArray<AActor*> Actors, int32 low, int32 high)
{
int32 a = partition(Actors, low, high);
quicksort(Actors, low, a - 1);
quicksort(Actors, a + 1, high);
}
These below are my interface header files. I wrote nothing in the interface cpp files because I want to implement them only by blueprints.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "CInterfaceActorManager.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UCInterfaceActorManager : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class F15TEST_API ICInterfaceActorManager
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ManageActor")
void ActorDestroyed(AActor* Actor, bool IsAir, bool IsAlly, bool IsMissile);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ManageActor")
void ActorEscaped(AActor* Actor, bool IsAir, bool IsAlly, bool IsMissile);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ManageActor")
void ActorSpawned(AActor* Actor, bool IsAir, bool IsAlly, bool IsMissile);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ManageActor")
void ActorInRange(AActor* Actor);
};
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "CInterfaceShowWidget.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UCInterfaceShowWidget : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class F15TEST_API ICInterfaceShowWidget
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void ShowWhite();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void ShowRed();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void ShowRedLock();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void ShowBlue();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void ShowX();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ShowWidget")
void DisableAll();
};
I think I literally copied my blueprint lines to c++ except for the sort functions on the bottom.
Here is what I was copying to c++.
This is ManageActorsInRange. It checks all actors’ horizontal distance to the player. If distance<200000 and it wasn’t in the ‘InRange(the range of 200000 distance units)’ array, the actor will be added to it and the player sends a few interface messages. I was quite stuck on sending interface messages because interfaces in my project should be implemented by blueprints and that made me confused.
This is AddActorToArray. It immediately adds the actor input to the array input. After some boolean checks there is another function. I want this function to be implemented by blueprints like the previous interfaces.
The question was too long so I didn’t upload the entire blueprints but if more blueprint lines are needed, I will upload it.
Anyone has some idea why I got the build error on top?