Problems Extending the Content Browser Menu

I am trying to extend the content browser menu system. After reading several tutorials and spending a couple days digging through the UE4 source I’ve narrowed my issue down to this…

I must convert from the FExtender object to this FContentBrowserMenuExtender in order to add it into the array. But I cannot figure out how to make that conversion. Any help would be greatly appreciated.

TSharedPtr<FExtender> HTImportExtender = MakeShareable(new FExtender);
HTImportExtender->AddMenuExtension("ContentBrowserImportAsset", EExtensionHook::After, NULL, FMenuExtensionDelegate::CreateStatic(&ImportMenuExtender::AddExtension));

FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
TArray<FContentBrowserMenuExtender> CBMenuExtenderDelegates = ContentBrowserModule.GetAllAssetContextMenuExtenders();
CBMenuExtenderDelegates.Add(FContentBrowserMenuExtender::BindSP(HTImportExtender));

Note the BindSP Call here does not work.

So to answer my own question. Here’s a solution that finally compiled. I post this here for 2 reasons. 1) If anyone else has this problem they can find it, and 2) If anyone knows my solution is wrong they can let me know! Thanks all.

CBMenuExtenderDelegates.Add(FContentBrowserMenuExtender::CreateLambda([&](){return HTImportExtender.ToSharedRef(); }));

With UE4.14, two little fixes are needed: array must be passed by reference and the shared pointer must be passed by copy:

TArray<FContentBrowserMenuExtender> & CBMenuExtenderDelegates = ContentBrowserModule.GetAllAssetContextMenuExtenders();
CBMenuExtenderDelegates.Add(FContentBrowserMenuExtender::CreateLambda([=]() {return HTImportExtender.ToSharedRef(); }));

Hello, I’ve write an article that covers the process of extending context menu: