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!