hi, I’m trying to create a simple custom asset editor but I’m having problems with the creation of the new window for the editor.
I already created a new custom asset, its factory and a new class that inherits FAssetTypeActions_Base and support my new asset.
I also created a new class that inherit FAssetEditorToolkit. One told me to create a simple widget and to register it within RegisterTabSpawners() function. Problem is, the engine crashes when it reach SNew(SGraphEditor) in my CreateViewportEditor() function and I don’t know what to do.
I tried commenting the line and return an empty pointer but it crashes anyway so I don’t really know what I’m doing wrong.
here’s the code if it can help:
.h
#pragma once
#include "CoreMinimal.h"
#include "AssetEditorToolkit.h"
#include "NotifyHook.h"
#include "GCObject.h"
#include "GraphEditor.h"
#include "PropertyEditorModule.h"
#include "ModuleManager.h"
/**
*
*/
class NOTANOTHERGRAPHASSISTANT_API AssetEditorGenericGraph:public FAssetEditorToolkit, public FNotifyHook, public FGCObject
{
public:
AssetEditorGenericGraph();
~AssetEditorGenericGraph();
// Inherited via FAssetEditorToolkit
virtual FName GetToolkitFName() const override;
virtual FText GetBaseToolkitName() const override;
virtual FText GetToolkitName() const override;
virtual FText GetToolkitToolTipText() const override;
virtual FLinearColor GetWorldCentricTabColorScale() const override;
virtual FString GetWorldCentricTabPrefix() const override;
virtual FString GetDocumentationLink() const override;
virtual void SaveAsset_Execute() override;
// IToolkit interface
virtual void RegisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
virtual void UnregisterTabSpawners(const TSharedRef<FTabManager>& TabManager) override;
// Inherited via FGCObject
virtual void AddReferencedObjects(FReferenceCollector & Collector) override;
private:
TSharedPtr<SGraphEditor>ViewportEditor;
TSharedPtr<class IDetailsView> PropertyWidget;
TSharedPtr<class IDetailsView> EditorSettingsWidget;
TSharedPtr<SGraphEditor>CreateViewportEditor();
TSharedRef<SDockTab> SpawnTab_Viewport(const FSpawnTabArgs & Args);
};
.cpp
#include "AssetEditorGenericGraph.h"
#define LOCTEXT_NAMESPACE "AssetEditorGenericGraph"
AssetEditorGenericGraph::AssetEditorGenericGraph()
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor costructor"));
CreateViewportEditor();
}
AssetEditorGenericGraph::~AssetEditorGenericGraph()
{
}
FName AssetEditorGenericGraph::GetToolkitFName() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetToolkitFName"));
return FName();
}
FText AssetEditorGenericGraph::GetBaseToolkitName() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetBaseToolkitName"));
return FText();
}
FText AssetEditorGenericGraph::GetToolkitName() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetToolkitName"));
return FText();
}
FText AssetEditorGenericGraph::GetToolkitToolTipText() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetToolkitToolTipText"));
return FText();
}
FLinearColor AssetEditorGenericGraph::GetWorldCentricTabColorScale() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetWorldCentricTabColorScale"));
return FLinearColor();
}
FString AssetEditorGenericGraph::GetWorldCentricTabPrefix() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetWorldCentricTabPrefix"));
return FString();
}
FString AssetEditorGenericGraph::GetDocumentationLink() const
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor GetDocumentationLink"));
return FString();
}
void AssetEditorGenericGraph::SaveAsset_Execute()
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor SaveAsset_Execute"));
}
void AssetEditorGenericGraph::RegisterTabSpawners(const TSharedRef<FTabManager>& TabManager)
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor RegisterTabSpawners"));
WorkspaceMenuCategory = TabManager->AddLocalWorkspaceMenuCategory(LOCTEXT("WorkspaceMenuAssetEditorGenericGraph", "Generic Graph Editor"));
auto WorkspaceMenuCategoryRef = WorkspaceMenuCategory.ToSharedRef();
FAssetEditorToolkit::RegisterTabSpawners(TabManager);
TabManager->RegisterTabSpawner(TEXT("TABID"), FOnSpawnTab::CreateSP(this, &AssetEditorGenericGraph::SpawnTab_Viewport)).SetDisplayName(LOCTEXT("GraphCanvasTab", "Viewport"));
}
void AssetEditorGenericGraph::UnregisterTabSpawners(const TSharedRef<FTabManager>& TabManager)
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor UnregisterTabSpawners"));
}
void AssetEditorGenericGraph::AddReferencedObjects(FReferenceCollector & Collector)
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor AddReferencedObjects"));
}
TSharedPtr<SGraphEditor> AssetEditorGenericGraph::CreateViewportEditor()
{
UE_LOG(LogTemp, Warning, TEXT("Asset editor START CreateViewportEditor"));
FGraphAppearanceInfo AppearanceInfo;
AppearanceInfo.CornerText = LOCTEXT("AppearanceCornerTextAssetEditorGenericGraph", "Generic Graph");
ViewportEditor = SNew(SGraphEditor);
FDetailsViewArgs Args;
Args.bHideSelectionTip = true;
Args.NotifyHook = this;
FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
PropertyWidget = PropertyModule.CreateDetailView(Args);
EditorSettingsWidget = PropertyModule.CreateDetailView(Args);
return ViewportEditor;
}
TSharedRef<SDockTab> AssetEditorGenericGraph::SpawnTab_Viewport(const FSpawnTabArgs& Args)
{
TSharedRef<SDockTab> SpawnedTab = SNew(SDockTab).Label(LOCTEXT("ViewportTab_Title", "Viewport"));
if (ViewportEditor.IsValid())
{
SpawnedTab->SetContent(ViewportEditor.ToSharedRef());
}
return SpawnedTab;
}
I also need a bit of help understanding what I need to implement in order to achieve a simple graph editor, i tried looking for documentation but I found almost nothing.