虚幻引擎4空白模块

3

我正在尝试进入虚幻引擎4模块开发,从空白模块开始入手,但在一开始就遇到了难题。

我通过一个非游戏模块的教程:https://wiki.unrealengine.com/An_Int...to_UE4_Plugins。我试着按照源代码进行操作,后来将所有内容修改为TestPlugin(因为我也无法按照教程操作成功)。

由于某种原因,每当我尝试在编辑器中激活该模块时,都会出现“找不到‘Module’模块”的错误。我正在努力弄清楚是否有遗漏,以下是我目前的代码:

../Engine/Plugins/TestPlugin/TestPlugin.uplugin

{
    "FileVersion" : 3,

    "FriendlyName" : "Test Plugin",
    "Version" : 1,
    "VersionName": "1.0",
    "EngineVersion" : 1579795,
    "Description" : "Description goes here",
    "Category" : "Test.Module",
    "CreatedBy" : "arhon",
    "CreatedByURL" : "http://stackoverflowcom",
    "CanContainContent" : "true",

    "Modules" :
    [
        {
            "Name" : "Module",
            "Type" : "Developer",
            "LoadingPhase" : "PreDefault"
        } 
    ]
}

../Engine/Plugins/TestPlugin/Source/TestPlugin/TestPlugin.cpp

(编程相关)
 void FTestPlugin::StartupTestPlugin()
    {
        if (ITestPlugin::IsAvailable())
        {
            UE_LOG(TestPlugin, Log, TEXT("%s"), ITestPlugin::Get().IsThisNumber42(42) ? TEXT("True") : TEXT("False"));
            UE_LOG(TestPlugin, Log, TEXT("%s"), ITestPlugin::Get().IsThisNumber42(12) ? TEXT("True") : TEXT("False"));
        }
    }

../Engine/Plugins/TestPlugin/Source/TestPlugin/TestPlugin.Build.cs

using UnrealBuildTool;

public class TestPlugin : ModuleRules
{
    public TestPlugin(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

        PrivateDependencyModuleNames.AddRange(new string[] { "TestPlugin" });

        DynamicallyLoadedModuleNames.AddRange(new string[] { "StandAlone" });
    }
}

../Engine/Plugins/TestPlugin/Source/TestPlugin/Public/ITestPlugin.h

#pragma once

#include "ModuleManager.h"
/**
* The public interface to this module.  In most cases, this interface is only public to sibling modules
* within this plugin.
*/
class ITestPlugin : public ITestPluginInterface
{

public:

    /**
    * Singleton-like access to this module's interface.  This is just for convenience!
    * Beware of calling this during the shutdown phase, though.  Your module might have been unloaded already.
    *
    * @return Returns singleton instance, loading the module on demand if needed
    */
    static inline ITestPlugin& Get()
    {
        return FModuleManager::LoadModuleChecked< ITestPlugin >("TestPlugin");
    }

    /**
    * Checks to see if this module is loaded and ready.  It is only valid to call Get() if IsAvailable() returns true.
    *
    * @return True if the module is loaded and ready to use
    */
    static inline bool IsAvailable()
    {
        return FModuleManager::Get().IsModuleLoaded("TestPlugin");
    }

    virtual bool IsThisNumber42(int32 num) = 0;
};

../Engine/Plugins/TestPlugin/Source/TestPlugin/Private/TestPluginPrivatePCH.h

(这是与编程相关的内容)
#include "ITestPlugin.h"

// You should place include statements to your module's private header files here.  You only need to
// add includes for headers that are used in most of your module's source files though.

../Engine/Plugins/TestPlugin/Source/TestPlugin/Private/TestPlugin.h

#pragma once

class TestPluginImpl : public ITestPlugin
{
public:
    /** IModuleInterface implementation */
    void StartupTestPlugin();
    void ShutdownTestPlugin();

    bool IsThisNumber42(int32 num);
};

../Engine/Plugins/TestPlugin/Source/TestPlugin/Private/TestPlugin.cpp

#include "TestPluginPrivatePCH.h"

#include "TestPlugin.h"

void TestPluginImpl::StartupTestPlugin()
{
}

void TestPluginImpl::ShutdownTestPlugin()
{
}

bool TestPluginImpl::IsThisNumber42(int32 num)
{
    return num == 42;
}

IMPLEMENT_MODULE(TestPluginImpl, TestPlugin)

当你的问题在首页展示时,人们只会看到前10个单词左右。因此请谨慎使用这些单词。 - Pascal Cuoq
谢谢你的建议。有没有任何建议如何重新表述问题? - arhon
我已经编辑过了,省略了“对于新手问题请原谅”或者其他类似的话。 - Pascal Cuoq
谢谢,我会记住的,下次发问题时会注意的(我相信未来还会有很多像这样糟糕的问题)。 - arhon
1个回答

2
.uplugin文件中,查看您的模块名称,然后在testplugin.cpp中,查看此行:
IMPLEMENT_MODULE(TestPluginImpl, TestPlugin)

我相信它们需要匹配。

例如:

"Modules" :
    [
        {
            "Name" : "NebulaAudioAnalysisPlugin",
            "Type" : "Runtime"
        } 
    ]

我的实现看起来像:

IMPLEMENT_MODULE(FNebulaAudioAnalysisPlugin, NebulaAudioAnalysisPlugin) 

我曾经艰难地发现了这一点...

你是绝对正确的。还有其他几个错误(我现在想不起来哪些了),最终我选择了插件较简单的版本,至少目前它满足了我的需求。但这绝对是正确的答案。 - arhon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接