This repository has been archived on 2026-05-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AgrarianGameArchive/Source/AgrarianGame/AgrarianEditorAutomationLibrary.cpp
T

47 lines
1.1 KiB
C++

// 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<AActor> 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<AActor>(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
}