Hello,
so i’ve added my method to the FEditorDelegates::OnAssetDragStarted multicast delegate. This works fine. I’ve done this because I want to be able to drag Levels/Maps into the viewport, which are then added as a streaming level to the currently open Level/Map. this works like I intend it to, however I am now unable to drag anything else into the scene. (e.g. I can’t drag any actors into the level). It feels like only my method I added is called and not the other editor methods.
Here is my code:
#pragma once
#include "CoreMinimal.h"
#include "Editor.h"
#include <Editor/UnrealEd/Classes/ActorFactories/ActorFactory.h>
#include <iostream>
class SNAPEDIT_API LevelMerger
{
public:
LevelMerger() {
FEditorDelegates::OnAssetDragStarted.AddRaw(this, &LevelMerger::OnAssetDragStarted);
}
~LevelMerger(){}
void OnAssetDragStarted(const TArray<FAssetData>& assetDatas, class UActorFactory* actorFactory);
};
and the .cpp file:
#include "LevelMerger.h"
#include "EditorLevelUtils.h"
#include "FileHelpers.h"
#include "Engine/LevelStreamingdynamic.h"
void LevelMerger::OnAssetDragStarted(const TArray<FAssetData>& assetDatas, class UActorFactory* actorFactory) {
for (FAssetData assetData : assetDatas)
{
if (assetData.AssetClass.ToString().Equals(L"World"))
{
UWorld* editorWorld = GEditor->GetEditorWorldContext().World();
if (editorWorld)
{
TArray<ULevelStreaming*> streamingLevels = editorWorld->GetStreamingLevels();
FString levelPath = assetData.PackageName.ToString();
ULevelStreaming* other = NULL;
for (ULevelStreaming* levelStream : streamingLevels) {
FString otherName = levelStream->GetWorldAssetPackageName();
UE_LOG(LogTemp, Warning, TEXT("%s"), *otherName);
if (otherName.Equals(levelPath)) {
other = levelStream;
}
}
if (other) {
TArray<AActor*> actorsInLevel = other->GetLoadedLevel()->Actors;
for (AActor* a : actorsInLevel) {
GEditor->SelectActor(a, true, true);
}
GEditor->edactDuplicateSelected(other->GetLoadedLevel(), false);
UEditorLevelUtils::CreateNewStreamingLevel(ULevelStreamingKismet::StaticClass(), other->GetWorldAssetPackageName() + "1", true);
}
else {
ULevelStreaming* level = UEditorLevelUtils::AddLevelToWorld(editorWorld, levelPath.GetCharArray().GetData(),
ULevelStreamingKismet::StaticClass());
}
}
}
else {
}
}
}
I initialize this class in the TickComponent function of a UActorComponent. The Component is set to tick in the editor, so LevelMerger gets initialized on the first Tick in the editor. I also made sure to only initialize it once.
Help would be appreciated since I wasn’t able to find anything similar online.
Thanks in advance