【问题标题】:UActorComponent derived class in plugin is not reacting for function calls插件中的 UActorComponent 派生类对函数调用没有反应
【发布时间】:2018-04-27 08:46:05
【问题描述】:

所以我在虚幻引擎 (4.15) 中创建项目插件时遇到了一点问题。所以让我们分解一下。 1.我创建了MyClass,它是从UActor Component派生的,也有这一行:

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))

2.我已将该组件添加到我的 GameMode 中。 3.然后我试图通过Get GameMode从类内部调用任何函数,然后转换为MyGameMode并获取MyClassComponent。 4.当我试图调用函数时,什么都没有发生。

我试图调试它,但它从来没有进入函数体,而是在函数之前和之后打印,效果很好。我还必须说,当函数直接编译到项目中时,它们可以 100% 正常工作!

这是我如何声明我的函数的示例:

UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
        void TestFunction();

void UMyClass::TestFunction()
{
    GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "hello there");
}

如果需要我不知道的更多信息,请告诉我。

MyClass 声明

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) 
class UMyClass : public UActorComponent 
{ 
GENERATED_BODY() 
public: 
UFUNCTION(BlueprintCallable, Category = "MyClass|Test") 
void TestFunction(); 
};

【问题讨论】:

  • "然后我试图通过转换为 GameMode 从类内部调用任何函数" 这是一个错字吗?您需要投射到MyGameMode,而不是GameModeGameMode 没有你的组件,你的 MyGameMode 有。
  • 是的,你是对的,我在那里犯了错误。我正在做 GetGameMode->Cast to MyGameMode->Get Component。
  • 请说明您的声明方式MyClass
  • 你所说的对我来说真的很奇怪,因为在 VS 15 中对我来说它编译得很清楚 o.0 还在问题中添加了类定义。
  • 我认为您在UMyClass 之前缺少YOURPLUGIN_API 说明符。

标签: c++ plugins unreal-engine4


【解决方案1】:

任何需要公开使用的类都需要导出其符号。

在 UE 插件中,这是通过 YOURPLUGIN_API 说明符实现的,其中 YOURPLUGIN 是插件的名称。

这反过来在导出时定义为__declspec(dllexport),在使用插件时定义为__declspec(dllimport)

所以你的类定义应该是这样的:

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) 
class MYPLUGIN_API UMyClass : public UActorComponent 
{
    ...
}

【讨论】:

    猜你喜欢
    • 2013-09-14
    • 2021-09-14
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多