Download

I am not able to edit my actor's components which is made in C++ in the Unreal Editor.

I just starting to learn the Unreal Engine with C++. I made an actor and gave it a StaticMeshComponent and made it editable with UPROPERTY(). But when I deploy the actor in viewport the mesh component is not editable and gives the following message.

TestSubject.h file:

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestSubject.generated.h"

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

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

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere)
		UStaticMeshComponent* flyingObj;
};

TestSubject.cpp file:

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


#include "TestSubject.h"

// Sets default values
ATestSubject::ATestSubject()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	flyingObj = CreateDefaultSubobject<UStaticMeshComponent>("StMesh");
}

// Called when the game starts or when spawned
void ATestSubject::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ATestSubject::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	FVector Lift = GetActorLocation();
	Lift.Z += 1.f;
	SetActorLocation(Lift);
}


Works for me in 4.27.1 without changes.

ViewportDetails2

The main problem is there is no root component set. If you look in the output log window when you drop your BP in the viewport, you will see a warning similar to:

BP_TestSubject_C_0 has natively added scene component(s), but none of them were set as the actor's RootComponent - picking one arbitrarily

You can set your component as root:

flyingObj = CreateDefaultSubobject<UStaticMeshComponent>("StMesh");
SetRootComponent(flyingObj);

… or You can create a USceneComponent as root and attach your component to the root:

USceneComponent* Root = CreateDefaultSubobject<USceneComponent>(TEXT("Root"));
SetRootComponent(Root);
flyingObj = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StMesh"));
flyingObj->SetupAttachment(Root);

Giving you a component hierarchy as created by default in Blueprint actors.

1 Like

Sorry, that solution didn’t work the problem still persists…
I tried both of the options that you provided - either make flyingObj the root component or make a USceneComponent object and make it the root component - they both failed

TestSubject.h file:

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

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestSubject.generated.h"

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

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

public:	
	// Called every frame
	virtual void Tick(float DeltaTime) override;

	UPROPERTY(EditAnywhere)
		UStaticMeshComponent* flyingObj;
		//USceneComponent* Root;
};

TestSubject.cpp file:

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


#include "TestSubject.h"

// Sets default values
ATestSubject::ATestSubject()
{
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

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

	flyingObj = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("StMesh"));
	SetRootComponent(flyingObj);
	//flyingObj->SetupAttachment(Root);
}

// Called when the game starts or when spawned
void ATestSubject::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ATestSubject::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	
	FVector Lift = GetActorLocation();
	Lift.Z += 1.f;
	SetActorLocation(Lift);
}

Try

UPROPERTY(EditAnywhere, BlueprintReadWrite)

If that still doesn’t work try changing your constructor in cpp to:

ATestSubject::ATestSubject(): Super()
1 Like