Let’s start by creating a new function, which will contain the whole process (you are free to apply the exact same principles as Events or any other set up). Let’s call it MyPointCloudFunction.

Creating new function in  Blueprint .

Creating new function in Blueprint.

Once the function is ready, add a local variable and call it MyPoints. Set the type of this variable to Point Cloud Point and convert it to an array by right-clicking on the blue bar symbol to the left of the name. This array will hold our intermediate data.

// Create an empty array to hold the points
TArray<FPointCloudPoint> MyPoints;
Create local array to hold the data.

Create local array to hold the data.


Now we can proceed to build the actual process, starting with populating our newly created array. For the purpose of this example, the array will be injected with 1000 randomly positioned, red points.

// Populate the MyPoints array with 1000 randomly positioned, red points
for (int32 i = 0; i < 1000; i++)
{
    // See FPointCloudPoint for more constructor versions
    MyPoints.Emplace(FMath::VRand() * 100, FColor::Red, true);
}
Populate the array with 1000 randomly positioned, red points.

Populate the array with 1000 randomly positioned, red points.


Once we have our data ready, we can create a new Point Cloud object from it, and it’s as simple as:

// Construct a Point Cloud asset
UPointCloud *MyPointCloud = UPointCloud::CreateFromData(MyPoints, bUseAsync)
Construct a Point Cloud asset

Construct a Point Cloud asset

Note the Use Async parameter - click here to learn more.


At this point you can do with the asset as you would with one imported through the Content Browser. In this example, we'll create a new Point Cloud Actor and assign our asset to it.

// Create new Point Cloud Actor
APointCloudActor* MyPointCloudActor = GetWorld()->SpawnActor<APointCloudActor>();

// Construct and assign the asset
MyPointCloudActor->SetPointCloud(UPointCloud::CreateFromData(MyPoints, false));
Assign the Cloud asset to a Point Cloud Actor.

Assign the Cloud asset to a Point Cloud Actor.


And that’s it - once the code or Blueprint is executed you should have a brand new, sphere-shaped, red Point Cloud, like this:

Final result.

Final result.


Here are the full code snippet and full-sized Blueprint screenshot of the complete process.

// Create an empty array to hold the points
TArray<FPointCloudPoint> MyPoints;

// Populate the MyPoints array with 1000 randomly positioned, red points
for (int32 i = 0; i < 1000; i++)
{
    // See FPointCloudPoint for more constructor versions
    MyPoints.Emplace(FMath::VRand() * 100, FColor::Red, true);
}

// Create new Point Cloud Actor
APointCloudActor* MyPointCloudActor = GetWorld()->SpawnActor<APointCloudActor>();

// Construct and assign the asset
MyPointCloudActor->SetPointCloud(UPointCloud::CreateFromData(MyPoints, false));

Complete Blueprint of the function.