How do I add a component on a constructor?

i m use Unreal Engine 5.2
.h:

pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Components/SplineComponent.h"
#include "ScreenSpline.generated.h"

UCLASS()
class SPLINE_API AScreenSpline : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AScreenSpline();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;
	void OnConstruction(const FTransform& Transform) override;

protected:
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
		UStaticMeshComponent* ScreenVolum;

        UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
		USceneComponent* Root;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
		USplineComponent* Spline;
}

.cpp:

// Fill out your copyright notice in the Description page of Project Settings.


#include "ScreenSpline.h"
#include "Components/SplineComponent.h"

// Sets default values
AScreenSpline::AScreenSpline()
{
	PrimaryActorTick.bCanEverTick = true;

Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
	SetRootComponent(Root);

Spline = CreateDefaultSubobject<USplineComponent>(TEXT("Spline"));
	Spline->SetupAttachment(Root);
}
void AScreenSpline::OnConstruction(const FTransform& Transform)
{
	Super::OnConstruction(Transform);

	ScreenVolum = NewObject<UStaticMeshComponent>(this, TEXT("Volum1"));
	this->AddInstanceComponent(ScreenVolum);
    ScreenVolum->RegisterComponent();
	ScreenVolum->CreationMethod = EComponentCreationMethod::Instance;
	this->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);
}

I want to implement dragging a spline in the editor to create a static mesh component when creating a new spline point. Now the code has been created, but the space for setting the static model is empty. I cannot set the static model for this component.

Except for the inability to manually set the model of ScreenVolum in the editor,

ScreenVolum ->SetStaticMesh (ConstructorHelpers: FOjectFinder<UStaticMesh>(TEXT ("StaticMesh '/Engine/BasicShapes/Cube. Cube'). Object);

Also unavailable, the editor cannot start.
I hope you can help me.
If possible, you can also provide some algorithms to determine the number of spline points and generate the same number of static models in the future. Thank you!

You’re using VisibleAnywhere for the component UPROPERTYs, that’s why it’s not editable. Use EditAnywhere or EditDefaultsOnly instead of VisibleAnywhere.

Or are you trying to set the mesh through C++?

Hello

Now
.h:

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Components")
		UStaticMeshComponent* ScreenVolum;

.cpp

ScreenVolum = NewObject<UStaticMeshComponent>(this, TEXT("Volum1"));
	this->AddInstanceComponent(ScreenVolum);
    ScreenVolum->RegisterComponent();
	this->AttachToComponent(RootComponent, FAttachmentTransformRules::SnapToTargetNotIncludingScale);

But when I click to select a model to assign to ScreenVolum in the editor, the editor will crash.

Hello

I replied to you in the previous post.