I'm try to do the C++ equivalent of Construct object from class in blueprint but doesn't seem to be working.

As the title says, I’m trying to construct this object arry, but when I go see if anything was added, it’s reads none and says both properties are invalid.

void USpatialInventory::initializeinventory()
{

AExtractionShooterCharacter* PlayerChar = Cast<AExtractionShooterCharacter>(GetOwner());

if (!PlayerChar)
{
	UE_LOG(LogTemp, Warning, TEXT("USpatialInventory owner is not AExtractionShooterCharacter!"));
	return;
}

if (!ContainerItemClass)
{
	UE_LOG(LogTemp, Warning, TEXT("ContainerItemClass is not valid!"));
	return;
}


//Spawn the item using the class
UContainerItem* Item = NewObject<UContainerItem>(this, ContainerItemClass);
Item->SetDimension(FIntPoint(1, 4));
Item->SetName(FName(TEXT("Pockets")));
Item->SetIcon(nullptr);
Item->SetIconRotated(nullptr);

if (!ContainerCellClass)
{
	UE_LOG(LogTemp, Warning, TEXT("ContainerCellClass is not valid!"));
	return;
}



//ccreate the cell
UContainerCell* Cell = NewObject<UContainerCell>(this, ContainerCellClass);
Cell->SetDimension(DefaultContainerDimension);
Cell->SetUsable(true);

//Create a default pocket
TArray<UContainerItem*> DefaultLocalContainerItems;

DefaultLocalContainerItems.SetNum(DefaultContainerDimension.X * DefaultContainerDimension.Y);
Cell->SetItems(DefaultLocalContainerItems);




TArray<UContainerCell*> Cells;
Cells.Add(Cell);


FContainerRowStuct Row;
Row.Cells = Cells;


TArray<FContainerRowStuct> ContainerRows;
ContainerRows.Add(Row);


Item->SetContainerRows(ContainerRows);


Items.Add(Item);

}

public:
// Sets default values for this component’s properties
USpatialInventory();

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Inventory")
TSubclassOf<UContainerItem> ContainerItemClass;

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Inventory")
TSubclassOf<UContainerCell> ContainerCellClass;

a lot of these are just local variables, are you actually setting it on the object?