I’m trying to familiarize myself more with UE’s C++ side of things. What code body should I generate for creating classes or structures? For example, let’s say I want to create an item class/struct for an inventory system. Do I create a new C++ file from within UE? If so, what type? Or do I just create an empty file inside of Visual Studio? What is the recommended method? Should I use the function library for this or struct factory? Does it matter?
I read the documentation here, but it says nothing about how to generate the file.
I usually create an empty file from the unreal editor called “GenericStructs” and put all the structs inside it (I do the same thing with enums).
There is no official rule on where to store them, my personal rule is “if it’s needed only in one class I Place it on the top of the class file, if it’s used in more than one class it goes inside GenericStructs file” (so you have to #include it in order to use it).
Yes, I mean an empty class.
Another important thing to remember is to mark both enums and structs as “BlueprintType”, otherwise they won’t be visible in the editor (Only in C++, but this could be a desired behaviour in certain cases).
You can declare functions inside structs, in this case you can see a constructor, but you can also init values directly with “=”, you can also have more than one constructor (for example FVector is a struct that you can init with a single float or with three floats obtaining different results)
I also prefer “GENERATED_BODY” but I guess that when I wrote my previous post (more than 2 years ago) I was still using the VSCode snippets that were not updated to the latest syntax🥲