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"

Plugin : How to properly include a struct

Hello,

in my Plugin I've got a Object which inherits from UObject. It's name is Watcher. Inside Watcher.h I declared a USTRUCT FMyStruct. The struct consists of some FVectors. Then I've got another Object inherited from UObject called Tracer. Watcher has a member of type Tracer. I want Tracer to do LineTraces , so i declared a method with Parameter MyStruct. Inside Watcher.h I included Tracer.h . Inside Tracer.h I included Watcher.h . Compiler can't resolve type of parameter FMyStruct in void Trace(..) . I've tried different includes. None worked for me. How do I include properly?

 #include "Tracer.h"
 #include "Watcher.generated.h"
 
 USTRUCT()
 struct FMyStruct
 {
     GENERATED_BODY()
 .............................................
 };
 
 
 UCLASS()
 class UWatcher : public UObject
 {
     GENERATED_BODY()
 
 private:
     FMyStruct values;
     UTracer* tracer;
 };

Tracer.h

  #include "Watcher.h"
 #include "Tracer.generated.h"
     
     UCLASS()
     class UTracer : public UObject
     {
         GENERATED_BODY()
         
     private:
         FHitResult Hitresult;
         void Trace(FMyStruct values);
     .................................................
     };
     
 


Product Version: UE 4.17
Tags:
more ▼

asked Nov 15 '17 at 10:02 PM in C++ Programming

avatar image

kosmopilot
17 3 5 7

avatar image ColdSteel48 Nov 15 '17 at 10:46 PM

I have the same problem - unfortunately you will have to move your struct to the tracer.h otherwise it will not work :(

avatar image ColdSteel48 Nov 15 '17 at 10:49 PM

Normally in C++ you would use forward declaration, but it doesn't work in this scenario when you are messing with USTRUCTS - onse possible solution is to promote it to UCLASS and then forward declare. Another solution I suppose would be to use TWeakPTR.

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

You can use forward type declarations here. For example in your header you can write

 // #include "Fish.h"
 void SomeFunctionEatingFish(class UFish* fresh);

without including files with UFish declarations. This method have limitations - you can declare only pointers or references of unknown classes and can't use any methods of this class in the file before including a header related to the class. When creating a .cpp file you still have to include all required headers to use your classes.

If it's not applicable you can move your UStruct declaration to a separate file and include it both from watcher and tracer files.

more ▼

answered Nov 15 '17 at 10:54 PM

avatar image

c4tnt
1k 12 8 29

avatar image kosmopilot Nov 15 '17 at 10:57 PM

Thanks, type declartion works :)

avatar image c4tnt Nov 15 '17 at 11:00 PM

Ooops, it's actually forward type declarations, I skipped that word...

(comments are locked)
10|2000 characters needed characters left
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