# If statement causes crash when given public int variable

**URL:** <https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050>\
**Category:** Getting Started & Setup\
**Tags:** actor-component, integer, unreal-engine, crash, question\
**Created:** [July 12, 2020, 10:25am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050 "2020-07-12T10:25:15Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 12, 2020, 10:25am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/1 "2020-07-12T10:25:15Z")

</div>

**only in UActorComponent** and it works when given a locally declared int

- if statements work in character class when given **Local and field int values**
- but in the ActorComponent the if statement works on everything except field declared integers

**is this a but or are ints not supposed to be in if statements**

**this only happens in ActorComponent**

```
if (IntegerValue == 3)
{
	// do something
}
```

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 12, 2020, 11:27am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/2 "2020-07-12T11:27:28Z")

</div>

Are integers supposed to cause crashes when in if statements

---

<div class="post-metadata">

**Author:** ![Mosel3y](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mosel3y](https://forums.unrealengine.com/u/Mosel3y)\
**Post date:** [July 12, 2020, 12:50pm UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/3 "2020-07-12T12:50:50Z")

</div>

The crash is probably coming from what happens after the if? What does the crash log say?

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 12, 2020, 1:15pm UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/4 "2020-07-12T13:15:38Z")

</div>

The crash log just directs me to the exact line the if statement is on

It happens with nothing inside of the if staement

**Could it be because of the int**

But then again it doesnt happen when it is a lacal int **only field**

---

<div class="post-metadata">

**Author:** ![Przemek2222](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Przemek2222](https://forums.unrealengine.com/u/Przemek2222)\
**Post date:** [July 12, 2020, 1:45pm UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/5 "2020-07-12T13:45:58Z")

</div>

Hello,

the only way to do such crash is to leave unasigned variable.

make sure you got some value inside this variable. If it crashes right click variable and add watch than check it’s value.

Again make sure you assign value to this variable for example `IntegerValue = 1`

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 13, 2020, 4:04am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/6 "2020-07-13T04:04:47Z")

</div>

well i did and it still happened

the if statement only causes crash when i use an **int that was declared in the header** even if i set the int value in the **ActorComponents constructor** it still causes crash when in if statement

---

<div class="post-metadata">

**Author:** ![Spidermined](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Spidermined](https://forums.unrealengine.com/u/Spidermined)\
**Post date:** [July 14, 2020, 1:05am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/7 "2020-07-14T01:05:22Z")

</div>

Have you tried launching a debug instance, e.g. from visual studio `Debug > Start Debugging`, because sometimes it gives more useful information when it catches a crash than the log.

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 14, 2020, 1:09am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/8 "2020-07-14T01:09:04Z")

</div>

**this question is answered in this**

> **[if statement causes crashes when given anything declared in header](https://forums.unrealengine.com/questions/970880/view.html)**
>
> if statements Inside Actor Component cause crashes when given (int, bool, float) that are declared in the actor components header is this something to do with ActorComponent and its header and the way things should be declared charater .h class...

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 14, 2020, 1:11am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/9 "2020-07-14T01:11:29Z")

</div>

thank you but it was because of how i **called the ActorComponent** not the if statement Silly me

**Thank you anyway**

---

<div class="post-metadata">

**Author:** ![BEnSon1101](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BEnSon1101](https://forums.unrealengine.com/u/BEnSon1101)\
**Post date:** [July 14, 2020, 1:12am UTC](https://forums.unrealengine.com/t/if-statement-causes-crash-when-given-public-int-variable/468050/10 "2020-07-14T01:12:23Z")

</div>

and this was figured out in this

> **[if statement causes crashes when given anything declared in header](https://forums.unrealengine.com/questions/970880/view.html)**
>
> if statements Inside Actor Component cause crashes when given (int, bool, float) that are declared in the actor components header is this something to do with ActorComponent and its header and the way things should be declared charater .h class...
