Using the various guides on the UE wiki and other sites, I’ve created a struct in it’s own .h file. After creating the struct, the project builds just fine, however, when I wish to use the struct in my AActor I’m given the error:
Cannot open include file: ‘…/Structs/ComponentStructure.h’: No such file or directory
This has me somewhat confused as the file is actually there.
I simply cannot grasp why the compiler says it can’t find the struct file. Any help is highly appreciated, as I’m somewhat stuck until I resolve this issue.
Judging by your sources directory structure #include “Structs/ComponentStruct.h” should work just fine.
I don’t know if this was a typo in your post or if your file has also this error but in ComponentMaster.h you are including Structs/ComponentMaster.h instead of Structs/ComponentStruct.h
What happens if you replace GENERATED_USTRUCT_BODY() with GENERATED_BODY() and USTRUCT() with USTRUCT(BlueprintType)? Just try and lets see what happens.
Nothing changes, still the same error. Is it really true that it should be this difficult creating a struct? I can’t seem ti find the issue, and it’s a bit strange
I think this might have something to do wiht the way I created the header file. I didn’t use the editor, but rather just created the header file and the subfolder “Struct” in Visual Studio. I’ve seen some question about this and what issues it may cause.
Folders in visual studio solution are not folders. Those are filters (virtual folders). If you add one inside visual studio the folder won’t be created on disk.
Exactly, which just lead me to a solution. The newly created header file was placed in the intermediate folder, instead of the source folder. If I were to create the header file in the source folder, it seems to work.
However, this doesn’t seem like the correct way to do it, or am I wrong?
When I need a simple header file for a struct definition I just create it in windows explorer (go to your project source, create the folder where you want to store it, right click, new text file, set its extension to .h)
That will work just fine. For actual classes I create them from the editor for convenience.
When you create the files from the windows explorer remember to add it to source control manually if you are using an scm.
Creating the header file in explorer, doesn’t make it show in VS. I suppose the project doesn’t see this file as included. How do you solve this? Just add existing item?
I tried that already, didn’t seem to work as the cpp file is still in the intermediate folder (I think) and messes with the build, giving me compile errors.
PERFECT! This seems to solve my issue within VS. I still cannot see the struct in the editor though. Any solution to this? It’s not that I really intend to use it in blueprints, but since the other cpp classes are present in the editor, I’d like the struct to be there too.