Simple Actor Constructor "already has a body"- error

Hey there,

I am just starting with unreal c++ and already struggling. I followed these tutorials:

How to spawn a simple cube in C++? - Programming & Scripting - Epic Developer Community Forums

I like to create a simple actor, but I cant compile due to some error. What is wrong?

HEADER:

UCLASS()
class MYFIRSTPROJECT_API ASimpleItem : public AActor
{
	GENERATED_BODY()

	UPROPERTY(Category = Meshes, VisibleAnywhere)
	TSubobjectPtr<UStaticMeshComponent> CubeMesh;
};

CPP:

ASimpleItem::ASimpleItem(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	CubeMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("CubeMesh"));
}

Error:

**
Warnung 1 warning C4996: TSubobjectPtr is deprecated and should no longer be used. Please use pointers instead.**

**Warnung 2 warning C4996: FPostConstructInitializeProperties is deprecated and was renamed to FObjectInitializer. Please use that type instead. **

Fehler 3 error C2084: Funktion ‘ASimpleItem::ASimpleItem(const FObjectInitializer &)’ hat bereits einen Funktionsrumpf

might be translated to : “( … ) already has a body”

Thanks alot!

Hi

So the main issue is that your constructor seems to need to be declared explicitly in the header now. Also you will need to change the object initializer type.

EDIT : updated as per comments.

Header:

UCLASS()
 class MYFIRSTPROJECT_API ASimpleItem : public AActor
 {
     GENERATED_BODY()

 ASimpleItem(const FObjectInitializer& ObjectInitializer);

     UPROPERTY(Category = Meshes, VisibleAnywhere)
     TSubobjectPtr<UStaticMeshComponent> CubeMesh;
 };

For more information see this forum post :

1 Like

I think it isn’t a good idea to put it in the header file.
Just put a declaration tthere

Oh that’s right, I misread the post I quoted. You merely need to explicitly declare the constructor in the header.

Thanks for pointing that out!