TArray<APointCloudScript::FPointCloudPoint> APointCloudScript::GeneratePointCloud()
{
TArray<FPointCloudPoint> PointCloudArray;
const int32 NumPoints = 100;
FRandomStream RandomStream;
for (int32 i = 1; i <= NumPoints; i++)
{
//The rest of the code here that creates a random vector and color...//
FPointCloudPoint Point;
Point.Vector = ResultVector;
Point.Color = RandomColor;
//Append to array
PointCloudArray.Add(Point);
}
return PointCloudArray;
}
Basically what I want to happen is for this GeneratePointCloud function to return an array of struct PointCloudPoint. But I am getting an error:
error C2039: ‘FPointCloudPoint’: is not a member of ‘APointCloudScript’
which do not makes sense to my newbie brain. I would appreciate any help!
Hello, thank you for your reply. Here is the copy of the entire method:
// Function to generate a point cloud with random points
TArray<APointCloudScript::FPointCloudPoint> APointCloudScript::GeneratePointCloud()
{
TArray<FPointCloudPoint> PointCloudArray;
const int32 NumPoints = 100;
FRandomStream RandomStream;
for (int32 i = 1; i <= NumPoints; i++)
{
// Step 1: Create a random unit vector
float RandomX = RandomStream.FRandRange(-1.0f, 1.0f);
float RandomY = RandomStream.FRandRange(-1.0f, 1.0f);
float RandomZ = RandomStream.FRandRange(-1.0f, 1.0f);
FVector RandomVector(RandomX, RandomY, RandomZ);
RandomVector.Normalize();
// Step 2: Get a random float to vary the scale of the vector
float RandomFloat = RandomStream.FRandRange(10.0f, 500.0f);
// Step 3: Multiply the vector and the float
FVector ResultVector = RandomVector * RandomFloat;
// Step 4: Add a random color
uint8 RandomR = RandomStream.RandRange(0, 255);
uint8 RandomG = RandomStream.RandRange(0, 255);
uint8 RandomB = RandomStream.RandRange(0, 255);
FColor RandomColor(RandomR, RandomG, RandomB, 255);
// Step 5: Create a PointCloudPoint and append it to the array
FPointCloudPoint Point;
Point.Vector = ResultVector;
Point.Color = RandomColor;
PointCloudArray.Add(Point);
}
return PointCloudArray;
}
I had them declared on these lines:
FVector RandomVector(RandomX, RandomY, RandomZ);
and
FColor RandomColor(RandomR, RandomG, RandomB, 255);
or should I have had also declared them somewhere else in the code?
As for point number 2, it is not necessary because I would be needing to edit them in the blueprints, but I’m going to add UPROPERTY if it’s gonna make the whole thing compile and work
TArray<APointCloudScript::FPointCloudPoint> APointCloudScript::GeneratePointCloud()
Look at this definition. Ur function return array of struct “FPointCloudPoint” and u say that class owns this struct but it is wrong.
“APointCloudScript::FPointCloudPoint” means that ur class owns this struct. Look at header and u will see that struct is independent.