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"

Class forward declaration not working with UFUNCTION

Hello everyone, I was wondering if anyone could tell me why I'm getting this obscure error and how to fix it/what I'm doing wrong. So, in this code snippet:

 #pragma once
 
 #include "../Public/TankAimingComponent.h"
 #include "GameFramework/Pawn.h"
 #include "Tank.generated.h"
 
 class UTankBarrel; //Forward declaration
 
 UCLASS()
 class BATTLETANKS_API ATank : public APawn
 {
     GENERATED_BODY()
 
 public:
     // Sets default values for this pawn's properties
     ATank();
     void AimAt(FVector);
 
     //Allows the blueprint to call this method
     UFUNCTION(BlueprintCallable, Category = Setup)
         void SetBarrelReference(UTankBarrel*);
 
 protected:
 
     UTankAimingComponent* tankAimingComponent = NULL;
 
     // Called when the game starts or when spawned
     virtual void BeginPlay() override;
 
 private:    
 
     // Called every frame
     virtual void Tick(float DeltaTime) override;
 
     // Called to bind functionality to input
     virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
 
     UPROPERTY(EditAnywhere, Category = Firing)
         float launchSpeed = 100000;
 
     
     
 };

I'm making a class forward declaration and using it in a function under UFUNCTION (Line 20), which to which i am aware should work without problem. However I'm getting the following error:

 Unrecognized type 'UTankBarrel' - type must be a UCLASS, USTRUCT or UENUM

I have the same declaration in another header file with a similar function that compiles and the only difference is it doesn't have the UFUNCTION macro. My UE4 version is 4.15.2.

Any help is appreciated and apologies if this was asked/solved before.

Product Version: UE 4.15
Tags:
more ▼

asked May 04 '17 at 12:43 PM in C++ Programming

avatar image

ErikssonJeny
1 1 2 4

avatar image ImVawx ♦♦ STAFF May 04 '17 at 02:13 PM

I don't really use forward declarations so forgive me if this is not the answer you are looking for. I generally declare things like this, when using game project C++ files:

      UFUNCTION(BlueprintCallable, Category = Setup)
      void SetBarrelReference(class UTankBarrel* InBarrel);

I suggest removing the class UTankBarrel declaration and change this UFUNCTION.

avatar image ErikssonJeny May 04 '17 at 02:24 PM

I tried it that way as you suggested and I'm still getting the same error, unfortunately.

avatar image ImVawx ♦♦ STAFF May 04 '17 at 02:31 PM

Have you made a class that is UTankBarrel, which is included in the project? Or, are you just trying to declare it?

avatar image ErikssonJeny May 04 '17 at 02:36 PM

Yes, I have made a class using the Editor, however I was told this way I don't create some problems by including header files in other header files and creating circular dependencies. As I said, in another class this works fine, it just doesn't have UFUNCTION in front of it.

I just want to declare it so that the function in this class compiles and doesn't need to worry about it.

avatar image ImVawx ♦♦ STAFF May 04 '17 at 02:45 PM

Did you compile the project before trying to use the class? I know it sounds odd but I have ran into issues of trying to use a type before its been compiled and getting errors like this.

You are right that you don't need to include the project headers in other project headers.

It's tough to figure out why you would have this issue because as long as you have made the UTankBarrel that is a component and that the class is declared as a UCLASS( ) in the BATTLETANKS_API, it should work.

avatar image ErikssonJeny May 04 '17 at 02:54 PM

I tried building, rebuilding and cleaning the whole solution and just the project, the same error popping up each time. I shrugged it as irrelevant, but perhaps the other two errors might have to do with it or lead to a solution?

 UnrealHeaderTool failed for target 'BattleTanksEditor' (platform: Win64, module info: D:\Users\<USER>\Documents\Unreal Projects\UnrealCourseSection5\BattleTanks\Intermediate\Build\Win64\BattleTanksEditor\Development\BattleTanksEditor.uhtmanifest, exit code: OtherCompilationError (5)).    BattleTanks    D:\Users\<USER>\Documents\Unreal Projects\UnrealCourseSection5\BattleTanks\Intermediate\ProjectFiles\
 
 EXEC    1    
 
 
 Error    MSB3075    The command ""C:\Program Files\Epic Games\UE_4.15\Engine\Build\BatchFiles\Build.bat" BattleTanksEditor Win64 Development "D:\Users\<USER>\Documents\Unreal Projects\UnrealCourseSection5\BattleTanks\BattleTanks.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.    BattleTanks    C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets    41    
 
 
avatar image ImVawx ♦♦ STAFF May 04 '17 at 02:59 PM

It looks like there is more going on then the missing UCLASS, USTRUCT, UENUM error.

Generally when you get the "exited with code 5" it is a issue with a macro, or you actually don't have permission to do that operation.

If you want, you can send me the project and I can try to look at it. You can either post it here or send me a PM on the forums.

If you do decide to send a project, you only need to include:

  1. Config

  2. Content

  3. Source

  4. .uproject

If you don't want to send your project, just go back to where you were when you got the "exited with code 5" error and try to figure out what went wrong.

avatar image ErikssonJeny May 04 '17 at 03:27 PM

I think I have found the culprit, I selected AStaticActor instead of UStaticMeshComponent when creating UTankBarrel, will see how it goes once I fix that.

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

1 answer: sort voted first

Yep, that fixed it. An incorrect class.

So, in summary you have to have a functioning class (that successfully compiles) for it to work with UFUNCTION, forward declaration by itself doesn't work.

Thank you for your help, Kyle!

more ▼

answered May 04 '17 at 03:38 PM

avatar image

ErikssonJeny
1 1 2 4

avatar image ImVawx ♦♦ STAFF May 04 '17 at 03:52 PM

No problem, glad to help.

(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