Place initial gameplay actors in test map
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user