gpt4 book ai didi

c++ - 插件中的 UActorComponent 派生类对函数调用没有反应

转载 作者:行者123 更新时间:2023-11-28 04:55:13 25 4
gpt4 key购买 nike

所以我在 Unreal Engine 中为 (4.15) 创建项目插件时遇到了一些问题。因此,让我们分解一下。1.我创建了派生自 UActor 组件的 MyClass 并且还有这一行:

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();
};

最佳答案

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

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

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

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

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

关于c++ - 插件中的 UActorComponent 派生类对函数调用没有反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47285168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com