首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >虚幻引擎4 CPP:'AsShared':不是'MyModule‘的成员

虚幻引擎4 CPP:'AsShared':不是'MyModule‘的成员
EN

Stack Overflow用户
提问于 2016-11-07 06:33:54
回答 1查看 3K关注 0票数 0

我是C++公司的纽比,试图从Unity3D迁移到虚幻引擎4。现在,我正在尝试编写我的第一个插件(UI插件和工具是我工作中非常重要的一部分),并坚持将OnClicked事件添加到SButton中,我从创建独立窗口插件开始添加一个按钮。

代码语言:javascript
复制
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给我这个错误

代码语言:javascript
复制
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\4.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\4.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\4.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\4.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\4.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

,请帮帮忙,我不知道发生了什么,谢谢你的建议!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-07 09:45:28

FAssistLibModule看起来像从IModuleInterface派生出来的,不是一个共享指针,所以您必须为OnClicked指定绑定的方法。

我认为用它代替

OnClicked(this, &FAssistLibModule::CollectBlueprintsButtonClicked)

使用

OnClicked(FOnClicked::CreateRaw(this, &FAssistLibModule::CollectBlueprintsButtonClicked))

OnClicked_Raw(this, &FAssistLibModule::CollectBlueprintsButtonClicked)

检查这个线程,我认为它是有用的:https://forums.unrealengine.com/showthread.php?78289-Slate-button-causes-the-editor-to-hang-when-instantiated&p=343287&viewfull=1#post343287

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40459104

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档