How to create PCGVolume with properly initialized extents in C++

I am trying to create PCGVolume programmatically in the following way:

#CustomPCGVolume.h

#pragma once

#include "CoreMinimal.h"
#include "PCGVolume.h"
#include "Components/BoxComponent.h"
#include "CustomPCGVolume.generated.h"

UCLASS()
class TESTSPLINEACTOR_API ACustomPCGVolume : public APCGVolume
{
	GENERATED_BODY()
public:
	ACustomPCGVolume(const FObjectInitializer& ObjectInitializer);
	// Box component to define the bounds of the PCGVolume
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
	UBoxComponent* BoxComponent;	
};


# CustomPCGVolume.cpp
#include "CustomPCGVolume.h"

ACustomPCGVolume::ACustomPCGVolume(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Create the BoxComponent and attach it to the root component
	BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxComponent"));
	BoxComponent->SetupAttachment(RootComponent); // Attach to the root component of the PCGVolume

	// Set the default extent of the box component
	BoxComponent->SetBoxExtent(FVector(3000.0f, 3000.0f, 500.0f)); // Example half extents
	BoxComponent->SetVisibility(true); // Make the component visible in the editor
	BoxComponent->SetHiddenInGame(false); // Ensure it is not hidden during gameplay
}

But when I attach PCGGraph to this volume and try to generate content (for the sake of simplicity, I do this in editor) - nothing happens. Judging by results of PCGVolume->GetBounds(), it seems that created volume has zero size.

The same PCG graph works well with PCGVolume created manually in the editor.

Is there any way to fix the problem? Perhaps it’s somehow possible to debug what exactly is going wrong.

Any help would be appreciated.

UBoxComponent* Bounds = NewObject<UBoxComponent>(this);
Bounds->SetBoxExtent(FVector(100000.0f));
Bounds->SetupAttachment(RootComponent);
Bounds->RegisterComponent();
Bounds->SetHiddenInGame(true);
Bounds->SetCollisionEnabled(ECollisionEnabled::NoCollision);

UPCGComponent* PCGComponent = NewObject<UPCGComponent>(this);
PCGComponent->RegisterComponent();
PCGComponent->SetGraph(PCGGraphInterface);
PCGComponent->Generate();

It’s a bit late but I came across the same issue you described and after a bit of googling I found a solution that seems to work for me and others so I wanted to share it with you on the forum as well. I tried different approaches with APCGVolume before but the only thing that seems to work is a UPCGComponent together with a custom UBoxComponent to set the required bounds