插件中派生的 UActorComponent class 未对函数调用做出反应
UActorComponent derived class in plugin is not reacting for function calls
所以我在 Unreal Engine 中为 (4.15) 创建项目插件时遇到了一些问题。因此,让我们分解一下。
1.I已经创建了派生自 UActor 组件的 MyClass,并且还有这一行:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
2.I已将该组件添加到我的 GameMode 中。
3.Then 我正在尝试通过 Get GameMode 从 class 内部调用任何函数,然后转换为 MyGameMode 并获取 MyClassComponent。
4.When 我正在尝试调用函数,但是什么也没有发生。
我试图调试它,但它从来没有进入函数体,而是在函数之前和之后打印,效果非常好。我还必须说,当函数直接编译到项目中时,它们可以 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();
};
任何需要公开使用的 classes 都需要导出其符号。
在 UE 插件中,这是通过 YOURPLUGIN_API
说明符实现的,其中 YOURPLUGIN
是插件的名称。
这又在导出时定义为 __declspec(dllexport)
,在使用插件时定义为 __declspec(dllimport)
。
所以您的 class 定义应该如下所示:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYPLUGIN_API UMyClass : public UActorComponent
{
...
}
所以我在 Unreal Engine 中为 (4.15) 创建项目插件时遇到了一些问题。因此,让我们分解一下。 1.I已经创建了派生自 UActor 组件的 MyClass,并且还有这一行:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
2.I已将该组件添加到我的 GameMode 中。 3.Then 我正在尝试通过 Get GameMode 从 class 内部调用任何函数,然后转换为 MyGameMode 并获取 MyClassComponent。 4.When 我正在尝试调用函数,但是什么也没有发生。
我试图调试它,但它从来没有进入函数体,而是在函数之前和之后打印,效果非常好。我还必须说,当函数直接编译到项目中时,它们可以 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();
};
任何需要公开使用的 classes 都需要导出其符号。
在 UE 插件中,这是通过 YOURPLUGIN_API
说明符实现的,其中 YOURPLUGIN
是插件的名称。
这又在导出时定义为 __declspec(dllexport)
,在使用插件时定义为 __declspec(dllimport)
。
所以您的 class 定义应该如下所示:
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class MYPLUGIN_API UMyClass : public UActorComponent
{
...
}