Problem adding class from editor

Hi all!

I’m currently trying to add a class to my project from the editor exactly the way it is done in the documentation
or in the ue4 c++ introduction videos.

Both the header and the source file are successfully created, but the source file contains only the #includes, without “MyClass::MyClass(<the objectinitializer parameter>) {}”.

So, i try to add it manually, but, when i try to compile, i get this error
“error C2084: function ‘MyClass::MyClass(const FObjectInitializer &)’ already has a body”.

May it be due to the fact that another engine version was used in the tutorials?
I really hope someone could help me, since i have no idea of what i’m doing wrong.

PS: Oh, and sorry for my english:).

Try this:

In your header file you should have GENERATED_BODY(). Change it to GENERATED_UCLASS_BODY()

With the upcoming 4.7, GENERATED_UCLASS_BODY is deprecated so you’ll want to have GENERATED_BODY(). The difference is that everything below is now private in the header so you want it to look like this:

class MyClass

      MyClass(const FObjectInitializer& ObjectInitializer);


And then the .cpp is similar to the video:

MyClass::MyClass(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{ }

In 4.6, you can either use this method or the method that’s updated for 4.7. Both will work just fine.

Thank you both guys, have a good day!

I think you stile are suposed to use the GENERATED_UCLASS_BODY()
If you want a constructor for your class.

I May be wrong tough so please correct me if I am. :slight_smile: