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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Forward Declaration for Structure

I can easily use forward declarations on classes, but the same mechanism does not work on structures. Let's say that in a single header file, I wrote this:

 struct FStructA;
 struct FStructB;
 
 USTRUCT(BlueprintType)
 struct FStructA
 {
     GENERATED_USTRUCT_BODY()
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
     FStructB TestB;
 };
 
 USTRUCT(BlueprintType)
 struct FStructB
 {
     GENERATED_USTRUCT_BODY()
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Data")
     FStructA TestA;
 };

When I compile it, the compiler always fail with the following message: "Unrecognized type 'FStructB' - type must be a UCLASS, USTRUCT or UENUM". This sort of error does not happen in ordinary C++. Is this a bug in UE or did I do something wrong?

Product Version: UE 4.12
Tags:
more ▼

asked Aug 14 '16 at 08:56 AM in C++ Programming

avatar image

Pelangi
251 22 34 42

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

2 answers: sort voted first

To expand a bit on what Shohei is saying. This is how structs work in UE4.

The absolute minimum you need is:

 USTRUCT( )
 struct FTestingStructA
 {
     GENERATED_BODY( );
 };

This includes having "F" before the name of the struct, or you will get a compiling error of, "Struct 'TestingStructA' has an invalid Unreal prefix, expecting 'FestingStructA'".

You need GENERATED_BODY( ), or you will get the compiling error of, "Expected a GENERATED_BODY() at the start of struct".

Thank you for submitting a bug report, however at this time we believe that the issue you are describing is not actually a bug with the Unreal Engine, and so we are not able to take any further action on this. If you still believe this may be a bug, please provide steps for us to reproduce the issue, and we will continue our investigation.

more ▼

answered Aug 15 '16 at 01:49 PM

avatar image

ImVawx ♦♦ STAFF
6.8k 114 18 127

avatar image Pelangi Aug 15 '16 at 03:38 PM

Thanks for the explanation. Shohei mentioned that the struct must be a pointer if I want to forward declare it. But USTRUCT cannot be treated as pointers can they? The compiler always give me an error if I created a pointer to a USTRUCT. In that example if I declare this, in another class (as UPROPERTY):

 FTestingStructA* pTestA;

then it won't compile.

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

You cannot forward declare a class or struct if you don't use it as a pointer. Pointers have fixed sizes so the compiler can allocate enough space for it. Non-pointers, on the other hand, are variable sizes and the compiler doesn't know how much memory to allocate at compile time.

Your illegal line is line 10 where you have attempted to use an incomplete class type. Change the variable to a pointer. If you do not change it to a pointer you will not be able to compile two structs that have a strong dependence on each other.

more ▼

answered Aug 14 '16 at 05:41 PM

avatar image

Shohei
1.1k 31 8 40

(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