# What could be causing my Custom Enum to crash the game?

**URL:** <https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011>\
**Category:** C++\
**Tags:** enumeration, ENUM, unreal-engine, question, CPP\
**Created:** [June 4, 2014, 10:39pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011 "2014-06-04T22:39:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![KGYTS\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KGYTS\_1](https://forums.unrealengine.com/u/KGYTS_1)\
**Post date:** [June 4, 2014, 10:39pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/1 "2014-06-04T22:39:52Z")

</div>

Hello, I’ve recently jumped from UDK and Unrealscript to UE4 and C++ so I feel that this is quite an obvious issue and it’s just my unfamiliarity with C++ that’s the problem, but I’ve been stuck on this for several hours now.

I’m defining a custom enum inside my PlayerController header like so:

![7753-ss+(2014-06-04+at+11.28.38).png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/7/3/c734aae4b3568b1f5ef7f527cdb8e028d28750b7.png)

Then I have it setting CState to CS\_Idle during the Player Controller’s initialization by setting it like so:

```
CState = CS_Idle;

```

All of this is fine and no issues arise from this, but when I try and modify the variable to indicate that the player is moving like in the image below, it crashes the game and editor:

![7757-ss+(2014-06-04+at+11.30.32)3.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/1/5/c1516bd778586484a7b8581801060ae68c4c4224.png)

I don’t fully understand Enumeration in C++ (Or C++ in general, I’m quite new to it though I have experience in Uscript and C#) so any help resolving this would be fantastic, thank you in advance.

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 4, 2014, 10:53pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/2 "2014-06-04T22:53:45Z")

</div>

Well, this is what I have in my code and it works perfectly fine.

I have two ENUMS… one is in my class just like yours and the other is in a STRUCT which is a bit different.

The one in my class is defined and assigned to like this:

```
UENUM()
namespace EWeaponState{
	enum Type{
		Idle,
		Using,
		Cooldown,
		Equipping,
		UnEquipping,
		Charging,
	};
}

...

// current weapon state 
	EWeaponState::Type CurrentState;

...

CurrentState = EWeaponState::Idle;

```

But… I have another ENUM that is used inside a STRUCT and I have to use it like this:

```
UENUM()
namespace EWeaponType{
	enum Type{
		Primary,
		Secondary,
		Tertiary,
		Shield,
	};
}

...

USTRUCT()
struct FMWeaponData{

	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditDefaultsOnly, Category = Type)
	TEnumAsByte<EWeaponType::Type> WeaponType;

        ...

	// defaults 
	FMWeaponData(){
		WeaponType = EWeaponType::Primary;
		...
	}

};

```

and that one is assigned in a Blueprint of that object.

Maybe try the way I do it in the class and see if it works!

Like this:

```
 // current weapon state 
    	EWeaponState::Type CurrentState;
    
    ...
    
    CurrentState = EWeaponState::Idle;
```

---

<div class="post-metadata">

**Author:** ![KGYTS\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KGYTS\_1](https://forums.unrealengine.com/u/KGYTS_1)\
**Post date:** [June 4, 2014, 11:14pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/3 "2014-06-04T23:14:19Z")

</div>

Thanks for the quick response!

I changed mine to reflect yours, everything else the same apart from the new way of tackling the enums, it built fine… But it still crashed upon attempting to move, which is quite confusing ☹

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [June 4, 2014, 11:20pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/4 "2014-06-04T23:20:46Z")

</div>

What calls MoveToMouseCursor, and what is the value of ‘this’ when it’s called?

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 4, 2014, 11:21pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/5 "2014-06-04T23:21:15Z")

</div>

Hmm… odd indeed. Are you sure it’s crashing at that line?

---

<div class="post-metadata">

**Author:** ![KGYTS\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KGYTS\_1](https://forums.unrealengine.com/u/KGYTS_1)\
**Post date:** [June 4, 2014, 11:23pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/6 "2014-06-04T23:23:10Z")

</div>

Oh this is interesting, it turns out the issue is more to do with how I am determining if a player should be in their ‘Idle’ state that is causing the crash  
(Which isn’t being calculated if they’re already in the Idle state, which made it seem like changing to ‘CS\_Moving’ was causing the crash, when really it wasn’t at all!  
Thank you for your help, AnXgotta, I now have a new problem to tackle haha.

---

<div class="post-metadata">

**Author:** ![AnxGotta](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AnxGotta](https://forums.unrealengine.com/u/AnxGotta)\
**Post date:** [June 4, 2014, 11:27pm UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/7 "2014-06-04T23:27:13Z")

</div>

Alright. Just FYI… if you build your game in `DebugGame Editor` mode. It should tell you the line of the error on crashes.

Just change it here

![7758-dbieg.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/1/a/e1a8a49449179eb990b619edce7df5c5dfe1124c.png)

rebuild your project and you should be good to go for debugging!

---

<div class="post-metadata">

**Author:** ![KGYTS\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KGYTS\_1](https://forums.unrealengine.com/u/KGYTS_1)\
**Post date:** [June 5, 2014, 7:58am UTC](https://forums.unrealengine.com/t/what-could-be-causing-my-custom-enum-to-crash-the-game/285011/8 "2014-06-05T07:58:17Z")

</div>

Oh, I was unaware of that, that’ll be extremely useful! Thank you!
