Hey Guys!
So I have a very frustrating problem which using UStructs at the moment. I have a UStruct in a custom .h call PlaneInfoStruct.h which I have some basic information about my pawn. It works find when I try editing these variables in its local object, but when I try to set them from an external .cpp it wont edit the values. I receive no error however and the values just stay at their defaults. PLEASE HELP!
Here is the .h file containing my struct
#pragma once
#include "PlaneInfoStruct.generated.h"
USTRUCT(BlueprintType)
struct FControllerInfo
{
GENERATED_USTRUCT_BODY()
public:
//GETTERS
FVector GetLocation(){ return Location; }
int32 GetLap() { return Lap; }
int32 GetCurrentTrackPoint() { return CurrentTrackPoint; }
int32 GetPreviousTrackPoint() { return PreviousTrackPoint; }
FLinearColor GetColor() { return Color; }
int32 GetScore() { return Score; }
int32 GetIndex() { return Index; }
//SETTERS
void SetLocation(FVector LocationToSet) { Location = LocationToSet; }
void SetLap(int32 LapToSet) { Lap = LapToSet; }
void SetCurrentTrackPoint(int32 TrackPointToSet) { CurrentTrackPoint = TrackPointToSet; }
void SetPreviousTrackPoint(int32 TrackPointToSet) { PreviousTrackPoint = TrackPointToSet; }
void SetColor(FLinearColor ColorToSet) { Color = ColorToSet; }
void SetScore(int32 ScoreToSet) { Score = ScoreToSet; }
void SetIndex(int32 IndexToSet) { Index = IndexToSet; }
// PROPERTIES
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
UClass* PlaneType = nullptr;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
FVector Location = FVector(0, 0, 0);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
int32 Lap = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
int32 CurrentTrackPoint = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
int32 PreviousTrackPoint = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
FLinearColor Color = FLinearColor(1, 0, 0, 1);
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
int32 Score = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Player Info")
int32 Index = 1;
};
Here is the Objects .h Whose Struct I want to Edit
#pragma once
#include "GameFramework/Pawn.h"
#include "PlaneInfoStruct.h"
#include "PlaneBase.generated.h"
UCLASS()
class AIRACES_API APlaneBase : public APawn
{
GENERATED_BODY()
public:
//Getters
FControllerInfo GetControllerInfo();
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category= "PlaneInfoStruct")
FControllerInfo ControllerInfo;
private:
APlaneBase();
virtual void BeginPlay() override;
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
};
Here is the external .cpp trying to edit values
// return average position of Planelocations
void URankingComponent::FigureOutPlaneLocationsAverage() {
TArray<AController*> LocalControllers = GameModeRef->GetControllersInSession();
TArray<FVector> LocalPlaneLocations;
FVector CombinedPlaneLocSize = FVector(0, 0, 0);
for (int32 i = 0; i < LocalControllers.Num(); i++) {
if (APlaneBase* ControlledPlane = Cast<APlaneBase>(LocalControllers[i]->GetPawn())){
ControlledPlane->GetControllerInfo().SetLocation(ControlledPlane->GetActorLocation()); /// TRYING TO SET VAULES HERE!
LocalPlaneLocations.Add(ControlledPlane->GetControllerInfo().GetLocation());
}
}
for (int32 i = 0; i < LocalPlaneLocations.Num(); i++) {
CombinedPlaneLocSize = CombinedPlaneLocSize + LocalPlaneLocations[i];
}
FVector AverageLoc = CombinedPlaneLocSize / LocalPlaneLocations.Num();
GameModeRef->SetPlaneLocationsAverage(AverageLoc);
}