# Unions and TUnion

**URL:** <https://forums.unrealengine.com/t/unions-and-tunion/5115>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 28, 2014, 1:30am UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115 "2014-05-28T01:30:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smartyMARTY](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/smartymarty/32/678332_2.png) [@smartyMARTY](https://forums.unrealengine.com/u/smartyMARTY)\
**Post date:** [May 28, 2014, 1:30am UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/1 "2014-05-28T01:30:35Z")

</div>

Unreal Community,

I am currently using the 4.1 branch of the Unreal source release. And I have run into a slight issue. Nothing that stops me, but is a question. Are there others with issues with compiling when using unions (assuming you have used any)? I have recently attempt to declare a simple union for a class and it stops building and says the declared property is not recognized. I just wanted to not have to waste any memory, but I went with a struct instead. The biggest reason I ask this is because there is a TUnion template in the documentation but when looking at the Core, it says that it is not included because it doesn’t compile. So my real question is, am I going to have to live without unions for UE4 programming?

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 28, 2014, 3:42am UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/2 "2014-05-28T03:42:08Z")

</div>

I’ve used unions just fine, as does the UE4 Source code 🙂

here’s the union I’ve used:

Note it is the typedef that I use in the PlayerController main class header

```auto

//declared above player controller header

typedef union floatdata {
  float f;
  unsigned long byteData;
} FloatUnionData;

```

```auto

//inside player controller header

//for converting bytes to float, uses union def
FloatUnionData FloatUnion;

```

```auto

**New Wiki**

I just composed a wiki on using unions in UE4 (mostly just the code)

https://wiki.unrealengine.com/Unions,_Different_Data_Types,_Same_Memory

Rama
```

---

<div class="post-metadata">

**Author:** ![smartyMARTY](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/smartymarty/32/678332_2.png) [@smartyMARTY](https://forums.unrealengine.com/u/smartyMARTY)\
**Post date:** [May 28, 2014, 5:32am UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/3 "2014-05-28T05:32:09Z")

</div>

I was declaring them just the same, as follows:

```auto

#pragma once

typedef union itemValue{
	float fValue;
	int32 iValue;
}ItemValue;

#include "GameFramework/Actor.h"
#include "Item.generated.h"

/**
 * 
 */
UCLASS()
class AItem : public AActor
{
	GENERATED_UCLASS_BODY()

	UPROPERTY()
	TSubobjectPtr<class UStaticMeshComponent> Mesh;

	UPROPERTY()
	FString ItemName;

	UPROPERTY()
	ItemValue Value;

//The Properties and Functions continue

```

But I still get a build error:

> [@](#):
>
> (28): error : In Item: Unrecognized type ‘ItemValue’  
> 18\>Error : Failed to generate code for MyProjectEditor - error code: 4

---

<div class="post-metadata">

**Author:** ![Rama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rama/32/882413_2.png) [@Rama](https://forums.unrealengine.com/u/Rama)\
**Post date:** [May 28, 2014, 5:58am UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/4 "2014-05-28T05:58:16Z")

</div>

Oooooh

🙂

You can’t make unions UPROPERTY() (at the moment)

You can always write a **Static Blueprint Library** to access your union data in whatever way you want, from any blueprint

like GetUnionAsFloat(ItemValue Value ) or GetUnionAsInt32(ItemValue Value)

You’ll have to declare your union in a header that you can include in your blueprint library class, or have your Blueprint Library class dependson AItem

**Wiki Tutorial on Blueprint Libraries**

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

Rama

---

<div class="post-metadata">

**Author:** ![smartyMARTY](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/smartymarty/32/678332_2.png) [@smartyMARTY](https://forums.unrealengine.com/u/smartyMARTY)\
**Post date:** [May 28, 2014, 1:00pm UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/5 "2014-05-28T13:00:53Z")

</div>

Ahhhhh, I see now Rama. Thanks. So unions cannot be a UPROPERTY(). That clears it up.

---

<div class="post-metadata">

**Author:** ![Noowai](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Noowai](https://forums.unrealengine.com/u/Noowai)\
**Post date:** [March 14, 2017, 12:59pm UTC](https://forums.unrealengine.com/t/unions-and-tunion/5115/6 "2017-03-14T12:59:01Z")

</div>

Hi there, did it change since then? Can I somehow use unions so I could see variables straight from blueprint editor? Or should I still use methods to pull any union value?  
Thanks
