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"

GENERATED_BODY vs GENERATED_UCLASS_BODY

I am learning C++ version of the FPS in UE following this: https://wiki.unrealengine.com/First_Person_Shooter_C%2B%2B_Tutorial

When I created a new class all the time there is GENERATED_BODY and the tutorial say I have to override the constructor and use AFPSGameMode(const FObjectInitializer& ObjectInitializer) but the compiler give me an error because I can't redeclare the constructor.

The get around of this is use GENERATED_UCLASS_BODY and then my constructor have the correct parameters but I dont know if I am doing it right.

I am new in UE so I really want to learn what I should use.

Product Version: UE 4.8
Tags:
more ▼

asked Jun 20 '15 at 10:50 PM in C++ Programming

avatar image

ubi
41 3 2 4

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

1 answer: sort voted first

Hello, ubi

Please note that with GENERATED_BODY(), a constructor is no longer necessary for each class (however, if you need a constructor, you can declare and define it as usual). The other difference is that, in comparison to GENERATED_UCLASS_BODY(), GENERATED_BODY() doesn't have the public specifier in it, so any class members that are declared after it are private by default (you can explicitly declare them as public). In your situation, please make sure that you have your constructor declared and defined correctly:

 //.h file
 //...
     GENERATED_BODY()
     
 public:
     AFPSGameMode(const class FObjectInitializer& ObjectInitializer);
 
 // .cpp file
 AFPSGameMode::AFPSGameMode(const class FObjectInitializer& ObjectInitializer)
 {
        // constructor functionality
 }

Hope this helped!

Have a great day!

more ▼

answered Jun 23 '15 at 06:50 AM

avatar image

Andrii Melnyk
1.8k 59 17 111

avatar image Jibberish Jul 05 '15 at 04:39 AM

I'm clear on the public scope issue, my question is not about that. Being new to UE4 myself, does this mean that we should never use GENERATED_UCLASS_BODY going forward? I found the "recommendation" that it not be used anymore in the 4.6 release notes, but I guess it's not officially deprecated?

I'm experiencing the same behavior described in the OP's question, because if I use GENERATED_BODY like in my code below, in the way you describe, I still get errors with my (truncated) code.

CODE

 // .h
  #pragma once
  #include "GameFramework/Character.h"
  #include "UETestCharacter.generated.h"
  
  UCLASS(config=Game)
  class AUETestCharacter : public ACharacter
  {
      GENERATED_BODY()
  
  public:
       AUETestCharacter(const class FObjectInitializer& ObjectInitializer);
  }...
  
  // .cpp   
  #include "UETestCharacter.h"
  #include "UETestCharacter.h"
  #include "BatteryPickup.h"
  
  AUETestCharacter::AUETestCharacter(const class FObjectInitializer &ObjectInitializer)
  {
          // constructor functionality
  }...

ERRORS

 Error    1    error code: OtherCompilationError (5)    C:\Users\Jibberish\Documents\Unreal Projects\UETest\Intermediate\ProjectFiles\Error    UETest
 Error    2    error MSB3073: The command ""C:\Program Files\Epic Games\4.8\Engine\Build\BatchFiles\Build.bat" UETestEditor Win64 Development "C:\Users\Jibberish\Documents\Unreal Projects\UETest\UETest.uproject" -rocket" exited with code -1.    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets    38    5    UETest
     3    IntelliSense: no instance of constructor "AUETestCharacter::AUETestCharacter" matches the argument list    c:\Users\Jibberish\Documents\Unreal Projects\UETest\Source\UETest\UETestCharacter.h    9    2    UETest

Many thanks!

avatar image Jibberish Jul 11 '15 at 01:31 AM

Never mind, it works now. I actually had a syntax error.

avatar image Karlsson600 Mar 27 '16 at 09:11 AM

This very very helped, I couldn't understand errors that I had, and difference between GENERATED_BODY and GENERATED_UCLASS_BODY regarding constructor "(const class FObjectInitializer& ObjectInitializer)" helped me a lot. It's my third day learning UE4. Thank you!

(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