I want to create a enum that contains the different types of weapons I will have (handgun, rifle, melee, etc). But if I define this enum in the c++ weapon class, my pawn’s animation blueprint can’t access it. (I need my animblueprint to access it, because I need to have the pawn doing a different animation depending on the current weapon type.)
So where can I define an enumeration so that everything, anywhere, can see it? I’m using C++, so I can’t declare one in the content browser. I also tried declaring it in MyProject.h, but that gave me errors. (?)
Thanks! Fixed it! I noticed that #pragma once is included in most of the source files by default, but not GB.h. Wonder why.
One more thing: is it bad to #include “GB.h” in both the .h and .cpp files for other classes? By default it’s only included in the .cpp, but I want to declare some of my custom enums in the .h.
Just like to pop in o share the way I handle enums and structs. This is mostly based off of a tutorial from the wiki by , so credits to him. 's my code:
This allows me to have enums and structs in a single organized file, but also have a bunch of INLINE functions in the header allowing for a sort of GameUtility script. It’s really handy for keeping stuff organized.
You actually had almost the right solution already in the original file, except you had the “#endif” for the GB_H in the wrong place – it should be at the end.
#ifndef __GB_H__
#define __GB_H__
#include "Engine.h"
#define COLLISION_PROJECTILE ECC_GameTraceChannel1
// #endif // this was wrong
#include "GB.generated.h"
UENUM(BlueprintType)
enum EItemAnimType
{
None UMETA(DisplayName = "None"),
Rifle UMETA(DisplayName = "Rifle"),
Handgun UMETA(DisplayName = "Handgun"),
Melee UMETA(DisplayName = "Melee")
};
#endif // this is what it should have been
@jwatte, that actually didn’t work for me for some reason, I needed the pragma once for it to work. No matter, “pragma once” compiles, that’s good enough for me
The resson for this is that (and am 99.99% sure about this).
That some where in the documentation it says NOT to use inclusion guards like #ifndefFILE_H …
But use the #pragma once i reserve the right to be wrong but am prety sure about it.
Am sure a UE 4 Dev drops by soon enofe and confirm this or not