# How can FVector pretends as USTRUCT?

**URL:** <https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928>\
**Category:** Editor Scripting\
**Tags:** ustruct, unreal-engine, vector, question\
**Created:** [November 7, 2017, 4:43am UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928 "2017-11-07T04:43:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rexion\_ize](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rexion\_ize](https://forums.unrealengine.com/u/Rexion_ize)\
**Post date:** [November 7, 2017, 4:43am UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928/1 "2017-11-07T04:43:44Z")

</div>

In Vector.h, `FVector` isn’t declared as `USTRUCT`. But in Blueprint, it works as `USTRUCT`. How is it possible? Can I make a similar one?

---

<div class="post-metadata">

**Author:** ![J0000J](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@J0000J](https://forums.unrealengine.com/u/J0000J)\
**Post date:** [November 7, 2017, 10:16am UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928/2 "2017-11-07T10:16:10Z")

</div>

Of course you can make a fake USTRUCT. The trick is to tell UHT to generate the reflection code without mess your own structure.

```
#if !CPP
USTRUCT(immutable, noexport, BlueprintType)
struct FTestVector
{
	UPROPERTY(EditAnyWhere, BlueprintReadWrite)
	float X;

	UPROPERTY(EditAnyWhere, BlueprintReadWrite)
	float Y;
};
#endif

struct FTestVector
{
	float X;
	float Y;
	void HelloVector() 
	{
		X = Y = 0;
	};
};

```

![219373-test.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/1/c/a1ca11eb724127a9ff30043b57752c95abd7c814.png)

See that? check NoExportTypes.h to see what happened in the Core module.

---

<div class="post-metadata">

**Author:** ![m.duman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@m.duman](https://forums.unrealengine.com/u/m.duman)\
**Post date:** [January 29, 2021, 1:05pm UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928/3 "2021-01-29T13:05:54Z")

</div>

Hello,  
This is very interesting, can you elaborate on what is happening here? If I set float X to some value, which value am I really setting? How does float X in the USTRUCT and in the normal struct synchronize?

---

<div class="post-metadata">

**Author:** ![m.duman](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@m.duman](https://forums.unrealengine.com/u/m.duman)\
**Post date:** [January 29, 2021, 1:33pm UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928/4 "2021-01-29T13:33:12Z")

</div>

I played around more, I am even more confused. I wrote this function inside a blueprint function library:

```
UFUNCTION(BlueprintPure)
static FVector TestFunction(FVector Vec);

FVector UGameplayAttributesLibrary::TestFunction(FVector Vec) {
	return Vec.Projection();
}

```

It can take in an FVector. When I call this from Blueprint, it will take in the FVector that is given in NoExportTypes.h. That FVector does not have a Projection method, but Unreal somehow understands we are talking about the C++ Vector and does the conversion. Then I return an FVector, which is the C++ FVector, but it converts back to the blueprint FVector so that I can set it inside blueprint. This is probably what the reflection system is meant to do from the start, I just never saw a class/struct be defined in two different places and used simultaneously. Very interesting.

---

<div class="post-metadata">

**Author:** ![Chillsteppp1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chillsteppp1](https://forums.unrealengine.com/u/Chillsteppp1)\
**Post date:** [August 29, 2023, 8:58am UTC](https://forums.unrealengine.com/t/how-can-fvector-pretends-as-ustruct/408928/5 "2023-08-29T08:58:12Z")

</div>

Check NoExportTypes.h . There is a another defination of FVector and it was marked as UStruct. So UHT will generate code for FVector in NoExportTypes.h .  
You may confused about why there are two definations of FVector. and how does it compiled pass? Actually, NoExportTypes.h has a CPP Macro, NoExportTypes.h will just contains some cpp headers when compile. So NoExportTypes.H is just for UHT to generate code.
