Calling Actor class functions in Plugin class

Hello Guys,
I am very new to unreal engine, I am working on Plugins in UE4 [Edit/Plugins/New Plugin/Editor Toolbar Button].
The plugin class I have created is “FAplhaPluginModule”. I have also created a “ABetaActor” class and have some functions.
Currently I want to use the functions of “ABetaActor” in my “FAplhaPluginModule” Is this possible? I tried to include “BetaActor.h” in my “FAplhaPluginModule.cpp” file, but the constant error I am getting is: “fatal error C1083: Cannot open include file: ‘BetaActor.generated.h’: No such file or directory”.
I have tried a bunch of solution posted by unreal community, but none of them worked. Please do let me know the ideal solution. Thanks in advance

First of all this is module class not plugin class, when you make a C++ project you also create module, but by default UE4 adds template of module class pasted using macro (you can see it in ProjectName.h and .cpp). UE4 code is modular and by creating C++ project or a plugin you create new modules which will be added to existing once, only difference between them is distribution method.

The Core module (which is the main root module) have a class which manage other modules:

With it you can gain access to there module class. like this:

FAlphaPluginModule& AlphaPlugin = FModuleManager::LoadModuleChecked<FAlphaPluginModule>("AlphaPlugin");

This will check if module is loaded (which will be since you be calling it from inside of it) if not load it and then return the module class. You can also skip load part if oyu know module is loaded using this function instead:

Other method is to use singleton which allows to access module class directly by creating static pointer (called singleton) then module is loaded and then make it accessible vis Get() function. It’s quite common practice in the engine and you may already encounter it, here simple example from source code how to set up:

https://github.com/EpicGames/UnrealEngine/blob/7d9919ac7bfd80b7483012eab342cb427d60e8c9/Engine/Source/Runtime/Online/Stomp/Private/StompModule.cpp

Ah i just realized you wanted to have opposite actor calling module class ^^’ can you send the compilation logs?

1>------ Build started: Project: UE4, Configuration: BuiltWithUnrealBuildTool Win32 ------
2>------ Build started: Project: ExtendEditor, Configuration: Development_Editor x64 ------
2>Creating makefile for hot reloading ExtendEditorEditor (no existing makefile)
2>Compiling game modules for hot reload
2>Using Visual Studio 2017 14.20.27508 toolchain (C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.20.27508) and Windows 10.0.17763.0 SDK (C:\Program Files (x86)\Windows Kits\10).
2>Building 3 actions with 48 processes…
2> [1/3] Module.AlphaPlugin.cpp
2>C:\develop\ExtendEditor\Plugins\AlphaPlugin\Source\AlphaPlugin\Private../…/…/…/…/Source/ExtendEditor/BetaActor.h(8): fatal error C1083: Cannot open include file: ‘BetaActor.generated.h’: No such file or directory
2>UnrealBuildTool : error : UBT ERROR: Failed to produce item: C:\svndevelop\ExtendEditor\Plugins\AlphaPlugin\Binaries\Win64\UE4Editor-AlphaPlugin-371.dll
2> (see …/Programs/UnrealBuildTool/Log.txt for full exception trace)
2>Total build time: 7.36 seconds (Parallel executor: 0.00 seconds)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ““C:\Program Files\Unreal Engine\UE_4.20\Engine\Build\BatchFiles\Build.bat” ExtendEditorEditor Win64 Development “C:\svndevelop\ExtendEditor\ExtendEditor.uproject” -WaitMutex -FromMsBuild” exited with code 5. Please verify that you have sufficient rights to run this command.
2>Done building project “ExtendEditor.vcxproj” – FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is my AlphaPlugin.cpp includes:

#include "AlphaPlugin.h"
#include "AlphaPluginStyle.h"
#include "AlphaPluginCommands.h"
#include "Misc/MessageDialog.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#include "LevelEditor.h"
#include "Runtime/Core/Public/HAL/PlatformFilemanager.h"
#include "Runtime/Engine/Classes/Engine/World.h"
#include "Runtime/Core/Public/HAL/FileManager.h"
#include "Runtime/Engine/Classes/GameFramework/Actor.h"
#include "../../../../../Source/ExtendEditor/BetaActor.h" [Trying to include BetaActor.h so that I could utilize the functions of that class]

2> [1/3] Module.AlphaPlugin.cpp
2>C:\develop\ExtendEditor\Plugins\AlphaPlugin\Source\AlphaPlugin\Private../…/…/…/…/Source/ExtendEditor/BetaActor.h(8): fatal error C1083: Cannot open include file: ‘BetaActor.generated.h’: No such file or directory
2>UnrealBuildTool : error : UBT ERROR: Failed to produce item: C:\svndevelop\ExtendEditor\Plugins\AlphaPlugin\Binaries\Win64\UE4Editor-AlphaPlugin-371.dll
2> (see …/Programs/UnrealBuildTool/Log.txt for full exception trace)
2>Total build time: 7.36 seconds (Parallel executor: 0.00 seconds)
2>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.MakeFile.Targets(44,5): error MSB3075: The command ““C:\Program Files\Unreal Engine\UE_4.20\Engine\Build\BatchFiles\Build.bat” ExtendEditorEditor Win64 Development “C:\svndevelop\ExtendEditor\ExtendEditor.uproject” -WaitMutex -FromMsBuild” exited with code 5. Please verify that you have sufficient rights to run this command.
2>Done building project “ExtendEditor.vcxproj” – FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is my AlphaPlugin.cpp includes:
#include “AlphaPlugin.h”
#include “AlphaPluginStyle.h”
#include “AlphaPluginCommands.h”
#include “Misc/MessageDialog.h”
#include “Framework/MultiBox/MultiBoxBuilder.h”
#include “LevelEditor.h”
#include “Runtime/Core/Public/HAL/PlatformFilemanager.h”
#include “Runtime/Engine/Classes/Engine/World.h”
#include “Runtime/Core/Public/HAL/FileManager.h”
#include “Runtime/Engine/Classes/GameFramework/Actor.h”
#include “…/…/…/…/…/Source/ExtendEditor/BetaActor.h” [Trying to include BetaActor.h so that I could utilize the functions of that class]

Ok can you close the editor (so you do proper compile instead of hot reload) and rebuild the solution? Also you sure you have UCLASS() in BetaActor.h? The error suggests that there problem with UHT code generation

Yes I am sure, there is UCLASS() in my BetaActor.h

All I am wondering is, Is it possible to call BetaActor.h (Actor class and its function) in my Plugin Module(AlphaPluginModule.cpp) file? If so please do let me know how?
Thank you

And did You finally found an answer to that question? I have exact the same issue as you had :slight_smile: