# Plugin : How to properly include a struct

**URL:** <https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733>\
**Category:** Plugins\
**Tags:** Struct, include, parameter, type, unreal-engine, Plugins, question\
**Created:** [November 15, 2017, 10:02pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733 "2017-11-15T22:02:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a95c0d08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a95c0d08](https://forums.unrealengine.com/u/anonymous_user_a95c0d08)\
**Post date:** [November 15, 2017, 10:02pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/1 "2017-11-15T22:02:33Z")

</div>

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);
    .................................................
    };

```

---

<div class="post-metadata">

**Author:** ![Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://forums.unrealengine.com/u/Anonymous_e5d5c0bf7d300728867097ff79906dbe)\
**Post date:** [November 15, 2017, 10:46pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/2 "2017-11-15T22:46:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_e5d5c0bf7d300728867097ff79906dbe](https://forums.unrealengine.com/u/Anonymous_e5d5c0bf7d300728867097ff79906dbe)\
**Post date:** [November 15, 2017, 10:49pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/3 "2017-11-15T22:49:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [November 15, 2017, 10:54pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/4 "2017-11-15T22:54:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a95c0d08](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a95c0d08](https://forums.unrealengine.com/u/anonymous_user_a95c0d08)\
**Post date:** [November 15, 2017, 10:57pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/5 "2017-11-15T22:57:51Z")

</div>

Thanks, type declartion works 🙂

---

<div class="post-metadata">

**Author:** ![c4tnt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@c4tnt](https://forums.unrealengine.com/u/c4tnt)\
**Post date:** [November 15, 2017, 11:00pm UTC](https://forums.unrealengine.com/t/plugin-how-to-properly-include-a-struct/409733/6 "2017-11-15T23:00:15Z")

</div>

Ooops, it’s actually forward type declarations, I skipped that word…
