Hello im trying to create a widget inside a slate but im having some troubles.
This is my cpp
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
#include "teste.h"
#include "testeStyle.h"
#include "testeCommands.h"
#include "LevelEditor.h"
#include "Editor.h"
#include "Runtime/UMG/Public/Components/Widget.h"
#include "Widgets/Docking/SDockTab.h"
#include "Widgets/Layout/SBox.h"
#include "Widgets/Text/STextBlock.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
static const FName testeTabName("teste");
#define LOCTEXT_NAMESPACE "FtesteModule"
void FtesteModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
FtesteStyle::Initialize();
FtesteStyle::ReloadTextures();
FtesteCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction(
FtesteCommands::Get().OpenPluginWindow,
FExecuteAction::CreateRaw(this, &FtesteModule::PluginButtonClicked),
FCanExecuteAction());
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
{
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender());
MenuExtender->AddMenuExtension("WindowLayout", EExtensionHook::After, PluginCommands, FMenuExtensionDelegate::CreateRaw(this, &FtesteModule::AddMenuExtension));
LevelEditorModule.GetMenuExtensibilityManager()->AddExtender(MenuExtender);
}
{
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension("Settings", EExtensionHook::After, PluginCommands, FToolBarExtensionDelegate::CreateRaw(this, &FtesteModule::AddToolbarExtension));
LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
}
FGlobalTabmanager::Get()->RegisterNomadTabSpawner(testeTabName, FOnSpawnTab::CreateRaw(this, &FtesteModule::OnSpawnPluginTab))
.SetDisplayName(LOCTEXT("FtesteTabTitle", "teste"))
.SetMenuType(ETabSpawnerMenuType::Hidden);
}
void FtesteModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.
FtesteStyle::Shutdown();
FtesteCommands::Unregister();
FGlobalTabmanager::Get()->UnregisterNomadTabSpawner(testeTabName);
}
UObject* FtesteModule::LoadAssetFromContent(FString Path, FString Name)
{
FString FullPath = Path + Name;
FStringAssetReference* assetRef = new FStringAssetReference(FullPath);
FStreamableManager assetLoader;
UObject* loadedAsset = nullptr;
loadedAsset = assetLoader.LoadSynchronous(*assetRef,true);
delete assetRef;
return loadedAsset;
}
TSharedRef<SDockTab> FtesteModule::OnSpawnPluginTab(const FSpawnTabArgs& SpawnTabArgs)
{
UBlueprint* loadedWidget = Cast<UBlueprint>(LoadAssetFromContent("/Content/Widgets", "MyUMG"));
if (loadedWidget)
{
UClass* tempWidget = loadedWidget->GeneratedClass;
createdWidget = CreateWidget<UUserWidget>(GEditor->GetEditorWorldContext().World(), tempWidget);
tempWidget = nullptr;
}
FText WidgetText = FText::Format(
LOCTEXT("WindowWidgetText", "Add code to {0} in {1} to override this window's contents"),
FText::FromString(TEXT("FtesteModule::OnSpawnPluginTab")),
FText::FromString(TEXT("teste.cpp"))
);
return SNew(SDockTab)
.TabRole(ETabRole::NomadTab)
[
// Put your tab content here!
SNew(SBox)
.HAlign(HAlign_Center)
.VAlign(VAlign_Center)
[
createdWidget->TakeWidget()
]
];
}
void FtesteModule::PluginButtonClicked()
{
FGlobalTabmanager::Get()->InvokeTab(testeTabName);
}
void FtesteModule::AddMenuExtension(FMenuBuilder& Builder)
{
Builder.AddMenuEntry(FtesteCommands::Get().OpenPluginWindow);
}
void FtesteModule::AddToolbarExtension(FToolBarBuilder& Builder)
{
Builder.AddToolBarButton(FtesteCommands::Get().OpenPluginWindow);
}
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FtesteModule, teste)
and this is my .h
// Copyright 1998-2018 Epic Games, Inc. All Rights Reserved.
#pragma once
#include "Engine.h"
#include "Runtime/Engine/Classes/Engine/StreamableManager.h"
#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"
#include "CoreMinimal.h"
#include "ModuleManager.h"
class FToolBarBuilder;
class FMenuBuilder;
class FtesteModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
/** This function will be bound to Command (by default it will bring up plugin window) */
void PluginButtonClicked();
UObject* LoadAssetFromContent(FString Path, FString Name);
UPROPERTY()
UUserWidget* createdWidget = nullptr;
private:
void AddToolbarExtension(FToolBarBuilder& Builder);
void AddMenuExtension(FMenuBuilder& Builder);
TSharedRef<class SDockTab> OnSpawnPluginTab(const class FSpawnTabArgs& SpawnTabArgs);
private:
TSharedPtr<class FUICommandList> PluginCommands;
};
This is my error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class TSharedRef<class SWidget,0> __cdecl UWidget::TakeWidget(void)" (__imp_?TakeWidget@UWidget@@QEAA?AV?$TSharedRef@VSWidget@@$0A@@@XZ) referenced in function "private: class TSharedRef<class SDockTab,0> __cdecl FtesteModule::OnSpawnPluginTab(class FSpawnTabArgs const &)" (?OnSpawnPluginTab@FtesteModule@@AEAA?AV?$TSharedRef@VSDockTab@@$0A@@@AEBVFSpawnTabArgs@@@Z) BuildingEscape C:\repos\03_building_escape\BuildingEscape\Intermediate\ProjectFiles\Module.teste.cpp.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static class UClass * __cdecl UUserWidget::StaticClass(void)" (__imp_?StaticClass@UUserWidget@@SAPEAVUClass@@XZ) referenced in function "class UUserWidget * __cdecl CreateWidget<class UUserWidget>(class UWorld *,class UClass *)" (??$CreateWidget@VUUserWidget@@@@YAPEAVUUserWidget@@PEAVUWorld@@PEAVUClass@@@Z) BuildingEscape C:\repos\03_building_escape\BuildingEscape\Intermediate\ProjectFiles\Module.teste.cpp.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: static class UUserWidget * __cdecl UUserWidget::CreateWidgetOfClass(class UClass *,class UGameInstance *,class UWorld *,class APlayerController *)" (__imp_?CreateWidgetOfClass@UUserWidget@@SAPEAV1@PEAVUClass@@PEAVUGameInstance@@PEAVUWorld@@PEAVAPlayerController@@@Z) referenced in function "class UUserWidget * __cdecl CreateWidget<class UUserWidget>(class UWorld *,class UClass *)" (??$CreateWidget@VUUserWidget@@@@YAPEAVUUserWidget@@PEAVUWorld@@PEAVUClass@@@Z) BuildingEscape C:\repos\03_building_escape\BuildingEscape\Intermediate\ProjectFiles\Module.teste.cpp.obj 1
I dont know how to fix this. I also added UMG to my Modules…
Thanks for your time!