Unreal Engine 4 CPP: 'AsShared': 不是 'MyModule' 的成员
Unreal Engine 4 CPP: 'AsShared': is not a member of 'MyModule'
我是 C++ 的新手,正在尝试从 Unity3D 迁移到 Unreal Engine 4. 现在我正在尝试编写我的第一个插件(UI 插件和工具是非常重要的部分我的工作)并坚持将 OnClicked 事件添加到 SButton
我从创建独立 Window 插件并添加一个按钮开始。
TSharedRef<SDockTab> FAssistLibModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs) {
FText WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Add code 111 222 to {0} in {1} to override this window's contents"),
FText::FromString(TEXT("FAssistLibModule::OnSpawnPluginTab")),
FText::FromString(TEXT("AssistLib.cpp"))
);
FText ButtonLabel = FText::FromString("Button?");
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SVerticalBox)
+SVerticalBox::Slot().VAlign(VAlign_Top)
[
SNew(STextBlock)
.Text(WidgetText)
]
+SVerticalBox::Slot().VAlign(VAlign_Top)
[
SNew(SButton)
.Text(ButtonLabel)
.OnClicked(this, &FAssistLibModule::CollectBlueprintsButtonClicked)
]
];}
编译UE后报错
Info Compiling game modules for hot reload
Info Performing 2 actions (4 in parallel)
Info Module.MyModule.cpp
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2039: 'AsShared': is not a member of 'FMyModuleModule'
Error D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Source\MyModule\Public\MyModule.h(10) : note: see declaration of 'FMyModuleModule'
Info C:\Program Files (x86)\Epic Games.13\Engine\Source\Runtime\Slate\Public\Widgets\Input\SButton.h(54): note: see reference to function template instantiation 'TBaseDelegate<FReply> TBaseDelegate<FReply>::CreateSP<UserClass,>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Info C:\Program Files (x86)\Epic Games.13\Engine\Source\Runtime\Slate\Public\Widgets\Input\SButton.h(54): note: see reference to function template instantiation 'TBaseDelegate<FReply> TBaseDelegate<FReply>::CreateSP<UserClass,>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Error D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Source\MyModule\Private\MyModule.cpp(89) : note: see reference to function template instantiation 'SButton::FArguments::WidgetArgsType &SButton::FArguments::OnClicked<FMyModuleModule>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2672: 'StaticCastSharedRef': no matching overloaded function found
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2672: 'TBaseDelegate<FReply>::CreateSP': no matching overloaded function found
Info ERROR: UBT ERROR: Failed to produce item: D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Binaries\Win64\UE4Editor-MyModule-6676.dll
Info Total build time: 46.77 seconds
请帮忙,我不明白发生了什么,感谢您的任何建议!
FAssistLibModule
看起来像是从 IModuleInterface
派生的,而不是共享指针,因此您必须指定要绑定到 OnClicked
的方法。
我认为替换
是正确的
OnClicked(this, &FAssistLibModule::CollectBlueprintsButtonClicked)
与
OnClicked(FOnClicked::CreateRaw(this, &FAssistLibModule::CollectBlueprintsButtonClicked))
或
OnClicked_Raw(this, &FAssistLibModule::CollectBlueprintsButtonClicked)
我是 C++ 的新手,正在尝试从 Unity3D 迁移到 Unreal Engine 4. 现在我正在尝试编写我的第一个插件(UI 插件和工具是非常重要的部分我的工作)并坚持将 OnClicked 事件添加到 SButton 我从创建独立 Window 插件并添加一个按钮开始。
TSharedRef<SDockTab> FAssistLibModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs) {
FText WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Add code 111 222 to {0} in {1} to override this window's contents"),
FText::FromString(TEXT("FAssistLibModule::OnSpawnPluginTab")),
FText::FromString(TEXT("AssistLib.cpp"))
);
FText ButtonLabel = FText::FromString("Button?");
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SVerticalBox)
+SVerticalBox::Slot().VAlign(VAlign_Top)
[
SNew(STextBlock)
.Text(WidgetText)
]
+SVerticalBox::Slot().VAlign(VAlign_Top)
[
SNew(SButton)
.Text(ButtonLabel)
.OnClicked(this, &FAssistLibModule::CollectBlueprintsButtonClicked)
]
];}
编译UE后报错
Info Compiling game modules for hot reload
Info Performing 2 actions (4 in parallel)
Info Module.MyModule.cpp
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2039: 'AsShared': is not a member of 'FMyModuleModule'
Error D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Source\MyModule\Public\MyModule.h(10) : note: see declaration of 'FMyModuleModule'
Info C:\Program Files (x86)\Epic Games.13\Engine\Source\Runtime\Slate\Public\Widgets\Input\SButton.h(54): note: see reference to function template instantiation 'TBaseDelegate<FReply> TBaseDelegate<FReply>::CreateSP<UserClass,>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Info C:\Program Files (x86)\Epic Games.13\Engine\Source\Runtime\Slate\Public\Widgets\Input\SButton.h(54): note: see reference to function template instantiation 'TBaseDelegate<FReply> TBaseDelegate<FReply>::CreateSP<UserClass,>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Error D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Source\MyModule\Private\MyModule.cpp(89) : note: see reference to function template instantiation 'SButton::FArguments::WidgetArgsType &SButton::FArguments::OnClicked<FMyModuleModule>(UserClass *,FReply (__cdecl FMyModuleModule::* )(void))' being compiled
Info with
Info [
Info UserClass=FMyModuleModule
Info ]
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2672: 'StaticCastSharedRef': no matching overloaded function found
Info c:\program files (x86)\epic games.13\engine\source\runtime\core\public\delegates\DelegateSignatureImpl.inl(181): error C2672: 'TBaseDelegate<FReply>::CreateSP': no matching overloaded function found
Info ERROR: UBT ERROR: Failed to produce item: D:\dev\repos\assist-lib-ue4\Plugins\MyModule\Binaries\Win64\UE4Editor-MyModule-6676.dll
Info Total build time: 46.77 seconds
请帮忙,我不明白发生了什么,感谢您的任何建议!
FAssistLibModule
看起来像是从 IModuleInterface
派生的,而不是共享指针,因此您必须指定要绑定到 OnClicked
的方法。
我认为替换
是正确的OnClicked(this, &FAssistLibModule::CollectBlueprintsButtonClicked)
与
OnClicked(FOnClicked::CreateRaw(this, &FAssistLibModule::CollectBlueprintsButtonClicked))
或
OnClicked_Raw(this, &FAssistLibModule::CollectBlueprintsButtonClicked)