# Initiallizing the variables of a structure

**URL:** <https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764>\
**Category:** Editor Scripting\
**Tags:** ustruct, initialize, unreal-engine, CPP, question\
**Created:** [August 12, 2014, 11:00am UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764 "2014-08-12T11:00:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![envenger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@envenger](https://forums.unrealengine.com/u/envenger)\
**Post date:** [August 12, 2014, 11:00am UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/1 "2014-08-12T11:00:47Z")

</div>

I have a structure

```
USTRUCT()
struct FIgnoreActor
{
	GENERATED_USTRUCT_BODY()

	AActor* IgnoredActor;

	int16 TimeIgnored;

	FIgnoreActor()
	{
		IgnoredActor = NULL;
		TimeIgnored = 0;
	}
};

```

When I create a new structure of the array, I want to initialize it in the following way.

```
FIgnoreActor TempStruct = FignoreActor(Actorxyp, 10);

```

But I am unable to do it. I can do it in this method now though

```
		FIgnoreActor TempStruct;
		TempStruct.IgnoredActor = OtherActor;
		TempStruct.TimeIgnored = TimeRemoval;

```

But i want to do it using `FignoreActor(`

---

<div class="post-metadata">

**Author:** ![eXi](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/exi/32/906583_2.png) [@eXi](https://forums.unrealengine.com/u/eXi)\
**Post date:** [August 12, 2014, 11:11am UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/2 "2014-08-12T11:11:11Z")

</div>

How about:

```
FIgnoreActor TempStruct = {Actorxyp, 10};

```

Isn’t that the normal way to initialize a struct in c++?

---

<div class="post-metadata">

**Author:** ![Duncan\_Dam](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Duncan\_Dam](https://forums.unrealengine.com/u/Duncan_Dam)\
**Post date:** [August 12, 2014, 11:15am UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/3 "2014-08-12T11:15:25Z")

</div>

Here you go add this in your struct.

```
FIgnoreActor(AActor* OtherActor, int16 TimeRemoval)
 {
 	IgnoredActor = OtherActor;
 	TimeIgnored = TimeRemoval;
 }
```

---

<div class="post-metadata">

**Author:** ![envenger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@envenger](https://forums.unrealengine.com/u/envenger)\
**Post date:** [August 12, 2014, 11:35am UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/4 "2014-08-12T11:35:10Z")

</div>

Yup but I think that method doesn’t work in UE.

---

<div class="post-metadata">

**Author:** ![Crzyhomer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Crzyhomer](https://forums.unrealengine.com/u/Crzyhomer)\
**Post date:** [August 12, 2014, 9:24pm UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/5 "2014-08-12T21:24:37Z")

</div>

This would be the proper way to do “constructors”, vs “initializer lists” below. Please add a UPROPERTY() above your actor pointer usage otherwise the object will be garbage collected shortly after it is instantiated.

Also, your example uses a version of your code created in stack memory rather than heap memory. It won’t last long, so you either need this to be a member variable of some other class (also with UPROPERTY) or it needs to be allocated with the new operator.

---

<div class="post-metadata">

**Author:** ![envenger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@envenger](https://forums.unrealengine.com/u/envenger)\
**Post date:** [August 12, 2014, 10:19pm UTC](https://forums.unrealengine.com/t/initiallizing-the-variables-of-a-structure/290764/6 "2014-08-12T22:19:48Z")

</div>

Ok I will add an UPROPERTY() on top.

The structure is initialized above a class declaration. Something I read in this tutorial.  
I don’t know if its the correct way to do it or now.

> **[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...
