x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

simple Actor Constructor "already has a body"- error

Hey there,

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

https://answers.unrealengine.com/questions/142180/how-to-spawn-a-simple-cube-in-c.html https://www.youtube.com/watch?v=vtcWrcscXos

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!

Product Version: Not Selected
Tags:
more ▼

asked Dec 05 '14 at 03:48 PM in C++ Programming

avatar image

DieOptimistin
21 1 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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 :

https://forums.unrealengine.com/showthread.php?52236-4-6-constructor-changes-am-confused&p=181552&viewfull=1#post181552

more ▼

answered Dec 06 '14 at 11:56 PM

avatar image

AlexM
150 7 9 17

avatar image birdfreeyahoo Dec 07 '14 at 01:31 AM

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

avatar image AlexM Dec 07 '14 at 02:39 AM

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!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question