I honestly don’t understand why there’s almost no proper explanation about this, I am new to coding on the engine. So far I got that structs help me organize custom variable data and that it basically looks like this:
I copied and pasted what you sent to an empty .h file, or copied it to the .h file of an actor, I suppose I am doing it wrong, should I be ‘including’ something for it?
Do I must create my structrs inside existing .h files (i.e. my classes where those structs are used) or there are some special place to store structs? Where I must place structs which I wan to use for multiple classes?
You can place structs in existing .h files, but remember the need to be declared before you use them, or what I like to do for organization, is create a new .h , header files can exist without code (.cpp) files. The .h file will only hold the structs. You can create a new .h file in VS by right clicking on a filter (folder) in the solution, Add New Item (change the directory to the appropriate source folder, I find it easier to do this instead of copying from intermedate folder) and name it (just remember to select the Header (.h) option). The build tool will pick up on the files and include them in the build.
You will need to use #pragma once and still include the filename.generated.h, then write all your structs, then just include the header file where you need it.
thanks for that great info, so is the actualy job of structs holding in some variables or sort of functions that can be used in different situations? is there anything more to it?
Thanks a lot for such nice info! I already dig it by myself in different places by small pieces, but you’ve gived us a very helpful and fullfilled compilation!
The structs may (and must) be used everywhere you need to store a typical data collections and work with each of them as with solid object. Also your structs can contain differend constructors and collection of methods to work with struct data, which can greatly increase coding speed and help you to beautefully organise your codespace. The easiest and best example of structs are the FVector, that contain 3 float variables and a lot of methods to change it or translate to something else.
that’s where I am troubled, I mean we put the variables with the struct inside an .h file but we define them inside a .cpp right? so how could I even use them in another cpp?