1

I create a new module in directory Engine/Source/Runtime/MyModule, and create MyModule.Build.cs, MyModule.cpp.

In MyModule.Build.cs, I write:


using UnrealBuildTool;

public class MyModule: ModuleRules
{
    public MyModule(ReadOnlyTargetRules Target) : base(Target)
    {
        bUseUnity = false;
        
        PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;
        
        PublicDependencyModuleNames.AddRange(
            new string[]
            {
                "Core",
                "Eigen",
            }
        );
            
        
        PrivateDependencyModuleNames.AddRange(
            new string[]
            {
            }
        );

        DynamicallyLoadedModuleNames.AddRange(
            new string[]
            {
                // ... add any modules that your module loads dynamically here ...
            }
        );

        PrivateDefinitions.AddRange(
            new string[]
            {
                
            }
        );

        UnsafeTypeCastWarningLevel = WarningLevel.Off;
        ShadowVariableWarningLevel = WarningLevel.Off;

        CppStandard = CppStandardVersion.Cpp17;
    }
}

And in MyModule.cpp, I write:

#include "Modules/ModuleInterface.h"
#include "Modules/ModuleManager.h"
#define LOCTEXT_NAMESPACE "MyModule"

class FMyModule: public IModuleInterface
{

public:
    FMyModule()
    {
    }


    // IModuleInterface interface
    virtual void StartupModule() override
    {
        // Do something
    }

    virtual void ShutdownModule() override
    {

    }

};

In my understanding, the modules in Engine/Source/Runtime are loaded defaultly, but it seems that, when I open an project, the FMyModule::StartupModule() is not called.

2
  • You should create a Plugin and put your module in it instead. This is exactly what they exist for. Engine modules are only built when you build the Engine, C++ is a compiled language, you can't just drop files in a folder and expect them to be run. Commented Aug 14, 2024 at 7:10
  • Thank you. I put this module in runtime because some engine modules depend on it. I finally solve this problem by load it with other engine module. @DatGeoudon Commented Aug 14, 2024 at 12:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.