I have made a singleton class named with lhcGamesingleton which header file is lhcGamesingleton.h located at MyProjectName/Source/MyProjectName. And then I wrote a plugin that must used lhcGamesingleton class but when include the lhcGamesingleton.h in MyPlugin.cpp there are compile was occured with “fatal error C1083: Cannot open include file: ‘lhcGamesingleton.h’: No such file or directory”.
I know that only public directory can be shared for other module but the game’s source does not have public directory by default. Does plugin can include project module’s header file ? Is it can be implemented?
Are you typing #include “lhcGamesingleton.h”? From a plugin, that folder is not in scope so you need to include a more complete path. Like, #include “…/…/MyProojectName/Source/MyProjectName/lhcGamesingleton.h” (depending on where your project is).
did you try adding a complete path to that ‘generated’ include file as well?
I have tried to include a complete path but error also occured with : fatal error C1083: Cannot open include file: ‘lhcGamesingleton.generated.h’: No such file or directory.
‘lhcGamesingleton.generated.h’ is included by lhcGamesingleton.h
I was able to include a custom actor class inside my plugin so it may be specific to singleton classes. How did you setup the singleton class? Was this done through Visual Studio or the editor? Could you post the header file for IhcGamesingleton.h?
It is lhcGamesingleton.h
In my plugin’s cpp file I include the lhcGamesingleton.h as “#include “D:/LHC_UE4_Projects/lhcPakTest/Source/lhcPakTest/lhcGamesingleton.h” and compile error " fatal error C1083: Cannot open include file: ‘lhcGamesingleton.generated.h’: No such file or directory” occured.
lhcGamesingleton.h was generated by UE4Editor.
This is my project folder’s snapshot:
The plugin’s cpp file which include the lhcGamesingleton.h is located at lhcPakTest\Plugins\AsyncPackageStreamer\Source\AsyncPackageStreamer\Public (marked with the red underline on the picture)
After further testing I found that adding the include statement inside the header file of the plugin rather than the source file should allow the code to compile successfully. Let me know if this change helps?
Does the code compile successfully if you remove the include statement completely? I don’t see the “cannot open include file” error that you mentioned originally in the screenshot. Based on the underlined parts of the screenshot it appears that AssetStreamer is your plugin which it doesn’t appear that any of the reported errors are referring to. If possible I would like you to build the project without the include to ensure that adding the include statement alone is breaking the compile.
As a note, plugins are intended to be project independent so that the plugin can be used across multiple projects. By including a class that is specific to a project, the plugin will then only work with that project or another project that has that class as well. A couple other alternatives that may help would be to make the plugin a module for the project instead. This will contain everything within the project with no external access needed. Another solution would be to add the class as part of the plugin. If the project requires the specific class it is more normal practice for the project to rely on the plugin than the plugin to rely on the project.
Let me know the result of compiling without the include statement and/or if any of the other information is helpful.
If I remove the include statement the code compiled successfully.I think the plugin can not include the specified header file which belong to the project who used the plugin. As you say the plugin is used for multi projects so it can not include the specified project’s header file. It is a logical issue. Am I right?
Thanks for your help !
I’m not sure exactly what you mean by “logical issue” but yes, trying to include a class that is specific to a project inside the plugin, especially when the plugin is used for other projects as well, will cause issues. Since the plugin is used for other projects I would say the best solution would be to, instead of including the class from the project in the plugin, actually create the class as part of the plugin. This way the project that needs the class can access it through the plugin, the plugin can still be used in other projects, and those other projects can ignore the class if they don’t need to use it.
You are right ! In my origin opinion the plugin want to use the project’s singleton class. For example :
UlhcGamesingleton * singletonObj = Cast(GEngine->GameSingleton);
I have to find another solution now. Thanks.
Hey, I’m doing something similar to this. I am trying to use use UE4Duino plugin in C++. I added dependency to Myproject.build.cs and exported the class by adding UE4DUINO_API right after the class keyword in plugin source header file. Still I cannot include plugin in my working code and it says " Cannot open include file: ‘Serial.h’: No such file or directory Serial_test D:\UE4_Projects\Mocap_test_corrected\Serial_test\Source\Serial_test\charact1.cpp 5". Please assist me with this.