How do I get a module name programmatically?

For example, how one would achieve this:

void FMyModule::StartupModule()


    FName myModuleName = /* ??? */;


I see module names are used in FModuleManager, but how can I acquire my module’s name programmatically in the module code?

Why would you need that when the string is already visible in your *IModuleInterface *?

One way to do it would be to declare the module name as a static variable of your module.

// .h
class ICustomModule : IModuleInterface
    static FName ModuleName;

// .cpp (outside a function)
FName ICustomModule::ModuleName = FName(TEXT("CustomModule"));

// in action
ICustomModule& Mod = FModuleManager::GetModuleChecked<ICustomModule>(ICustomModule::ModuleName);