StarArrayGen.h
#pragma once
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Core/Public/Math/Vector.h"
#include "Core/Public/Math/UnrealMathUtility.h"
#include "MyGame/MyGameEnums.h"
#include "MyGame/MyGameStructs.h"
#include <random>
#include "Containers/Array.h"
#include "StarArrayGen.generated.h"
/**
*
*/
UCLASS()
class MYGAME_API UStarArrayGen : public UObject
{
GENERATED_BODY()
public:
UStarArrayGen();
UFUNCTION(BlueprintCallable, Category = "Star Generation")
TArray<FVector> GetStar();
private:
std::mt19937 mtRand;
float coreRatio = 0.15;
float minStarDistance = 30;
float rotationStrength = 300;
float gravity = 10;
float galaxySize = 1600;
float armCount = 2;
float armSpread = 0.4;
FVector NextVec(float min, float max);
};
StarArrayGen.cpp
#include "StarArrayGen.h"
UStarArrayGen::UStarArrayGen()
{
}
TArray<FVector> UStarArrayGen::GetStar()
{
TArray<FVector> NewStar;
int counter = 0;
while (counter++ < 20)
{
FVector v = NextVec(-1, 1);
NewStar.Add(v);
}
return NewStar;
}
FVector UStarArrayGen::NextVec(float min, float max)
{
std::uniform_real_distribution<> distr(min, max);
return FVector(distr(mtRand), distr(mtRand), 0);
}
Okay, my problem: I am absolutely new to C++. (My native programming language is Perl.) I was brought in after the previous C++ coder on this project disappeared. I need to bring ‘TArray GetStar();’ into a level blueprint.
The problem - if I make that function static, it can’t use any of the higher math functions that are needed.
If I don’t make it static, the level blueprint wants a target and I’m not even sure what that means except that the blueprint wants something.