// Copyright Epic Games, Inc. All Rights Reserved. #include "AgrarianEditorAutomationLibrary.h" #include "Engine/World.h" #if WITH_EDITOR #include "Editor.h" #endif AActor* UAgrarianEditorAutomationLibrary::SpawnActorInEditorWorld(TSubclassOf ActorClass, const FVector& Location, const FRotator& Rotation, const FString& ActorLabel) { #if WITH_EDITOR if (!ActorClass) { return nullptr; } UWorld* EditorWorld = GEditor ? GEditor->GetEditorWorldContext().World() : nullptr; if (!EditorWorld) { return nullptr; } FActorSpawnParameters SpawnParameters; SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; SpawnParameters.ObjectFlags = RF_Transactional; AActor* SpawnedActor = EditorWorld->SpawnActor(ActorClass, Location, Rotation, SpawnParameters); if (!SpawnedActor) { return nullptr; } if (!ActorLabel.IsEmpty()) { SpawnedActor->SetActorLabel(ActorLabel, true); } SpawnedActor->MarkPackageDirty(); EditorWorld->MarkPackageDirty(); return SpawnedActor; #else return nullptr; #endif }