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

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

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

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.

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;

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 :frowning:

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

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

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.

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

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

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