# How do you use global UStructs in C++ ?

**URL:** <https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [January 10, 2020, 3:05am UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224 "2020-01-10T03:05:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_72ac72801](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_72ac72801](https://forums.unrealengine.com/u/anonymous_user_72ac72801)\
**Post date:** [January 10, 2020, 3:05am UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/1 "2020-01-10T03:05:48Z")

</div>

I have my FTestStruct compiled successfully. I created the .h file from within visual studio and included it in the header MyProjectName.h. I am at a loss as to how to actually create a variable in another class with it. How Would I call it? All i want to do is put 3 values into it exactly like you would with an FVector.

```auto

#pragma once
#include "CoreMinimal.h"
#include "LocalRoomVectorGrid.generated.h"

USTRUCT()
struct FTestStruct
{
    GENERATED_BODY()

public:

    UPROPERTY(EditAnywhere)
        int32 Value1 = 0;

    UPROPERTY(EditAnywhere)
        int32 Value2 = 0;

    UPROPERTY(EditAnywhere)
        int32 Value3 = 0;

    FTestStruct()
    {

    }
};

```

When i try the following in MyCharacter.CPP I get the error : error C2440: ‘’: cannot convert from ‘initializer list’ to ‘FTestStruct’

```auto

**FTestStruct Test = FTestStruct(1, 2, 3);**

```

---

<div class="post-metadata">

**Author:** ![Aaron1178](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aaron1178](https://forums.unrealengine.com/u/Aaron1178)\
**Post date:** [January 10, 2020, 3:45am UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/2 "2020-01-10T03:45:26Z")

</div>

You have no constructor that takes the parameters as described.

I have found a forum post on structure initialization which can be found at [Structs, how to initialize one as a variable? - C++ Gameplay Programming - Unreal Engine Forums](https://forums.unrealengine.com/development-discussion/c-gameplay-programming/63324-structs-how-to-initialize-one-as-a-variable)

If you don’t wish to specify a constructor with all your structure parameters, you can also do something like the following:

```auto

FTestStruct Test = FTestStruct();

Test.Value1 = 1;
Test.Value2 = 1;
Test.Value3 = 1;

// And so forth

```

Or specify a constructor to take your variables

```auto

#pragma once
#include "CoreMinimal.h"

#include "LocalRoomVectorGrid.generated.h

USTRUCT()
struct FTestStruct
{
    GENERATED_BODY()

public:

    UPROPERTY(EditAnywhere)
        int32 Value1 = 0;

    UPROPERTY(EditAnywhere)
        int32 Value2 = 0;

    UPROPERTY(EditAnywhere)
        int32 Value3 = 0;

    FTestStruct()
    {}

    FTestStruct(int32 Value1Param, int32 Value2Param, int32 Value3Param) : Value1(Value1Param), Value2(Value2Param), Value3(Value3Param)
    {}
};

```

And call like so:

```auto

FTestStruct Test(1,2,3);

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_72ac72801](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_72ac72801](https://forums.unrealengine.com/u/anonymous_user_72ac72801)\
**Post date:** [January 10, 2020, 3:51am UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/3 "2020-01-10T03:51:45Z")

</div>

THANK YOU VERY VERY MUCH.  
That is exactly what i was doing wrong.  
And thank you for explaining more than one method!

---

<div class="post-metadata">

**Author:** ![Fieol](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fieol/32/1104383_2.png) [@Fieol](https://forums.unrealengine.com/u/Fieol)\
**Post date:** [January 10, 2020, 6:13am UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/4 "2020-01-10T06:13:24Z")

</div>

You can also use

```auto

GENERATED_USTRUCT_BODY()

```

instead of GENERATED\_BODY()

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_72ac72801](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_72ac72801](https://forums.unrealengine.com/u/anonymous_user_72ac72801)\
**Post date:** [January 10, 2020, 6:11pm UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/5 "2020-01-10T18:11:33Z")

</div>

> [@Fieol](#):
>
> You can also use
> 
> ```auto
> 
> GENERATED_USTRUCT_BODY()
> 
> ```
> 
> instead of GENERATED\_BODY()

Is there any reason to use one over the other?  
I read on the wiki: “In case you are looking for GENERATED\_USTRUCT\_BODY, in 4.11+, GENERATED\_BODY() should be used instead.”

> **[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 — https://unrealcommunity.wiki/! You will be able to find content from...

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [January 10, 2020, 6:33pm UTC](https://forums.unrealengine.com/t/how-do-you-use-global-ustructs-in-c/136224/6 "2020-01-10T18:33:05Z")

</div>

Generated\_Body() makes a call to Generated\_Struct() if necessary.  
It doesn’t matter, can use any you like.
