Hey guys,
Just got a question as I’m still pretty new to Unreal C++ and I’m just wondering how you guys handle UStructs that you need to call globally.
Do you guys just put them all into one header file and then call that header file wherever you need it and if so do you guys also do the same with ENUMS?
Also, do you guys use a certain class like a UObject, or blueprint function libraries to do this?
There is no right or wrong way to handle this. Developers will have different preferences depending on their project requirements.
One option would be to store them in the project’s header file, although I am not a fan of this solution as I like to keep the header of the project fairly light.
Another option, as you mentioned is to keep them in separate header files. This is the approach I usually go for. I have a library imported as a plugin that I use for common structs and enums which are useful across multiple projects. Or I create an empty header file for both global structs and enums which are project-specific.
A third option is to keep the structs and enums defined close to the data they represent. For example, if it’s an enum used to represent different navigation types, then it makes sense to declare it somewhere near your pawn and then just include the appropriate header.
One piece of advice I will give is to keep your implementations consistent. There is nothing worse than working with a project where some enums/structs are declared in a separate header, some in classes and some in the project base. It becomes a nightmare to find data.
I wouldn’t include them in blueprint function libraries as that’s not the purpose of that class.
Again, it’s really down to the project and the design choice of the programmer. As long the implementation makes sense and you’re not including unnecessary header data where it’s not needed then you’re good to go.
Hey, I’m now getting an issue with my Header files not getting the generated include.
I have them in the source file within the public folder yet when I generate project files I get nothing. Wondering if I’m missing a step in this process? They do have the UENUM, USTRUCT so shouldn’t the header tool pick up on that?
Glad you found my answer helpful. If you wouldn’t mind marking it as correct in case other people have similar questions
If you created an empty class (NONE) in the Unreal Editor, you will need to manually add the .generated.h yourself. Close visual studio and restart the editor. Once open, go to File->Generate Visual Studio Files.
If the generated header still isn’t there, delete the “Intermediate” directory inside your project and then restart. Unreal should re-serialise all classes again.
Feel like this unreal project is broken lol. Now other files are missing their generated headers…
I will give this a shot in a new project and see how it handles it.