October3d55/NewCAVESystemCpp/Source/NewCAVESystemCpp/Private/NewCAVESystemCppBPLibrary.cpp

704 lines
20 KiB
C++
Raw Blame History

#include "NewCAVESystemCppBPLibrary.h"
#include "NewCAVESystemCpp.h"
#include "MISC/PackageName.h"
#include "ImageUtils.h"
#include "Framework/Application/SlateApplication.h"
#include "Components/InputComponent.h"
#include "LevelSequence.h"
#include "MovieScene.h"
#include "Camera/CameraComponent.h"
#include "Sections/MovieSceneCameraCutSection.h"
#include "Tracks/MovieSceneCameraCutTrack.h"
UNewCAVESystemCppBPLibrary::UNewCAVESystemCppBPLibrary(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
FName UNewCAVESystemCppBPLibrary::GetStreamingLevelNameFromActor(AActor * Actor)
{
if (Actor != nullptr)
{
return Actor->GetLevel()->GetOuter()->GetFName();
}
return NAME_None;
}
ULevel* UNewCAVESystemCppBPLibrary::GetLevelFromActor(AActor* Actor)
{
if (Actor != nullptr)
{
return Actor->GetLevel();
}
return NULL;
}
UWorld* UNewCAVESystemCppBPLibrary::GetWorldFromContext(UObject * WorldContextObject)
{
return GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
}
bool UNewCAVESystemCppBPLibrary::IsInWorldEditor(UObject * WorldContextObject)
{
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
if (World)
{
return World->WorldType == EWorldType::Editor;
}
return false;
}
bool UNewCAVESystemCppBPLibrary::IsInWorldGame(UObject * WorldContextObject)
{
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
if (World)
{
return World->WorldType == EWorldType::Game;
}
return false;
}
bool UNewCAVESystemCppBPLibrary::IsInWorldPIE(UObject * WorldContextObject)
{
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
if (World)
{
return World->WorldType == EWorldType::PIE;
}
return false;
}
//EWorldType::Type UNewCAVESystemCppBPLibrary::GetWorldType(UObject * WorldContextObject)
//{
// return GEngine->GetWorldFromContextObjectChecked(WorldContextObject)->WorldType;
//}
ULevel * UNewCAVESystemCppBPLibrary::GetPersistentLevel(UWorld * World)
{
return World->PersistentLevel;
}
TArray<ULevelStreaming*> UNewCAVESystemCppBPLibrary::GetStreamingLevelList(UObject * WorldContextObject)
{
UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::ReturnNull);
if (World)
{
return World->GetStreamingLevels();
}
TArray<ULevelStreaming*> EmptyLevelStreamingList;
return EmptyLevelStreamingList;
}
ULevel * UNewCAVESystemCppBPLibrary::GetLevelFromStreamingLevel(ULevelStreaming * StreamingLevel)
{
return StreamingLevel->GetLoadedLevel();
}
void UNewCAVESystemCppBPLibrary::GetAllActorsOfClassInLevel(const UObject * WorldContextObject, TSubclassOf<AActor> ActorClass, ULevel * Level, bool IsIncludeChild, TArray<AActor*>& OutActors)
{
// We do nothing if no is class provided, rather than giving ALL actors!
if (ActorClass && Level)
{
for (AActor* Actor : Level->Actors)
{
if(IsValid(Actor))
{
if (!IsIncludeChild)
{
if (Actor->GetClass() == ActorClass )
{
OutActors.Add(Actor);
}
}
else
{
if (Actor->IsA(ActorClass))
{
OutActors.Add(Actor);
}
}
}
}
}
}
bool UNewCAVESystemCppBPLibrary::IsMapExists(const FString & InName, FString &OutLongPackageName, FString &OutFileName)
{
bool bOutSuccess = FPackageName::SearchForPackageOnDisk(InName, &OutLongPackageName, &OutFileName);
return bOutSuccess;
}
void UNewCAVESystemCppBPLibrary::DestroyComponent(UActorComponent * Component, bool bPromoteChildren)
{
Component->DestroyComponent(bPromoteChildren);
}
ENetRole UNewCAVESystemCppBPLibrary::GetActorNetRole(AActor * Actor)
{
return Actor->GetLocalRole();
}
bool UNewCAVESystemCppBPLibrary::IsActorOwnedBy(AActor * Actor, AActor * Owner)
{
return Actor->IsOwnedBy(Owner);
}
bool UNewCAVESystemCppBPLibrary::IsActorLocallyControlled(AActor * Actor)
{
return Actor->HasLocalNetOwner();
}
template<class T>
bool UNewCAVESystemCppBPLibrary::ClonePropertyInfo(T *_Scr, T *_Des,bool OnlySaveGameFlag)
{
typedef struct PropertyInfo
{
FProperty *Property = nullptr;
FString PropName;
FString CPPType;
FString CPPMacroType;
EPropertyFlags flags = EPropertyFlags::CPF_None;
uint8 *PDATA = nullptr;
bool operator==(const PropertyInfo&da)
{
return PropName == da.PropName&&CPPType == da.CPPType&&CPPMacroType == da.CPPMacroType&&flags == da.flags;
}
}PropertyInfo;
auto StuffInf = [OnlySaveGameFlag](T *_Target)->TMap<FString, PropertyInfo>
{
TMap<FString, PropertyInfo>KVCmp;
for (TFieldIterator<FProperty> PropIt(_Target->GetClass()); PropIt; ++PropIt)
{
FProperty* Property = *PropIt;
auto PropName = Property->GetName();
auto CPPType = Property->GetCPPType();
auto flags = Property->GetPropertyFlags();
FString CPPMacroType;
Property->GetCPPMacroType(CPPMacroType);
auto PDATA = Property->ContainerPtrToValuePtr<uint8>(_Target);
auto CanSet = (flags & EPropertyFlags::CPF_Edit) == EPropertyFlags::CPF_Edit;
if (OnlySaveGameFlag)
{
CanSet = CanSet && ((flags & EPropertyFlags::CPF_SaveGame) == EPropertyFlags::CPF_SaveGame);
}
if (CanSet)
{
PropertyInfo cInf;
cInf.PropName = PropName;
cInf.Property = Property;
cInf.CPPType = CPPType;
cInf.CPPMacroType = CPPMacroType;
cInf.PDATA = PDATA;
cInf.flags = flags;
verify(!KVCmp.Contains(PropName));
KVCmp.Add(PropName, cInf);
}
}
return KVCmp;
};
TMap<FString, PropertyInfo> srcInf = StuffInf(_Scr);
TMap<FString, PropertyInfo> desInf = StuffInf(_Des);
for (auto it : srcInf)
{
if (desInf.Contains(it.Key))
{
auto desValue = desInf[it.Key];
//verify(it.Value == desValue);
desValue.Property->CopySingleValue(desValue.PDATA, it.Value.PDATA);
}
}
return true;
}
template<class T>
TArray<T*>
UNewCAVESystemCppBPLibrary::GetChildComponent(const AActor* actor)
{
TArray<T*> subCompArr;
//TArray<UActorComponent*> subCmps = actor->GetComponentsByClass(T::StaticClass());
TArray<UActorComponent*> subCmps;
actor->GetComponents(T::StaticClass(),subCmps,false);
for (UActorComponent* it : subCmps)
{
T* subComp = Cast<T>(it);
if (subComp)
{
subCompArr.Add(subComp);
}
}
return subCompArr;
}
AActor* UNewCAVESystemCppBPLibrary::CloneActorSimple(const UObject* WorldContextObject, AActor* InputActor)
{
UWorld* World = WorldContextObject->GetWorld();
//UE_LOG(LogTemp, Log, TEXT("Actor Duplication"));
FActorSpawnParameters params;
params.Template = InputActor;
UClass* ItemClass = InputActor->GetClass();
AActor* const SpawnedActor = World->SpawnActor<AActor>(ItemClass, params);
return SpawnedActor;
}
AActor* UNewCAVESystemCppBPLibrary::CloneActorComplex(AActor* TargetActor, FTransform SpawnTransform, AActor* Owner, bool OnlySaveGameFlag)
{
if (TargetActor && TargetActor->GetClass()->IsValidLowLevel() && GWorld.GetReference())
{
FActorSpawnParameters SpawnParm;
SpawnParm.Template = TargetActor;
SpawnParm.SpawnCollisionHandlingOverride = TargetActor->SpawnCollisionHandlingMethod;
SpawnParm.Owner = Owner;
auto defObj = TargetActor->GetClass()->GetDefaultObject<AActor>();
if (defObj)
{
SpawnTransform.SetScale3D(SpawnTransform.GetScale3D() / defObj->GetActorRelativeScale3D());
}
auto RetActor = GWorld.GetReference()->SpawnActor<AActor>(TargetActor->GetClass(), SpawnTransform, SpawnParm);
if (!RetActor)
{
return nullptr;
}
CloneChildActorAndCmp(TargetActor, RetActor, OnlySaveGameFlag);
return RetActor;
}
return nullptr;
}
AActor* UNewCAVESystemCppBPLibrary::CloneActor(AActor* InputActor)
{
if (InputActor)
{
//Init Setup
UWorld* World = InputActor->GetWorld();
//Setup spawn para to all data from InputActor
FActorSpawnParameters params;
params.Template = InputActor;
//Spawn Actor Action
UClass* ItemClass = InputActor->GetClass();
AActor* const SpawnedActor = World->SpawnActor<AActor>(ItemClass, params);
CloneChildActorAndCmp(InputActor, SpawnedActor, false);
return SpawnedActor;
}
else
{
UE_LOG(LogTemp, Warning, TEXT("Kickstart BPL: Invalid InputActor"));
return nullptr;
}
}
AActor * UNewCAVESystemCppBPLibrary::CloneActorPro(AActor* InputActor, TArray<AActor*>& OutAttachedActos, bool IncludedAttachedActors,
EAttachmentRule InLocationRule,
EAttachmentRule InRotationRule,
EAttachmentRule InScaleRule,
bool bInWeldSimulatedBodies)
{
//Call Comp Function
AActor* SpawnedActor = CloneActor(InputActor);
//Init Setup
UWorld* World = InputActor->GetWorld();
TArray<AActor*> tempChildActors;
InputActor->GetAllChildActors(tempChildActors);
#pragma region Clone Attached Actors?
if (IncludedAttachedActors)
{
//Also Clone Attached Actors from "Input Actor"
TArray<AActor*> AttachedActors; //For Out AttachedActors
InputActor->GetAttachedActors(AttachedActors);
//For loop
for (AActor* tempAttachedActor : AttachedActors)
{
if (!tempChildActors.Contains(tempAttachedActor))
{
//Setup spawn para to all data from InputActor
FActorSpawnParameters tempParams;
tempParams.Template = tempAttachedActor;
//Spawn Actor Action
UClass* tempItemClass = tempAttachedActor->GetClass();
AActor* tempSpawnedActor = World->SpawnActor<AActor>(tempItemClass, tempParams);
//Use to "DEFINE" the AttachRules. Declear is not allow when packaging plugin
FAttachmentTransformRules tempAttachRules = FAttachmentTransformRules(InLocationRule, InRotationRule, InScaleRule, bInWeldSimulatedBodies);
//Attach to Parent
tempSpawnedActor->AttachToActor(
SpawnedActor,
tempAttachRules);
AActor& temp2Actor = *tempSpawnedActor;
//Add to Array
OutAttachedActos.Add(tempSpawnedActor);
}
}
}
#pragma endregion
return SpawnedActor;
}
bool UNewCAVESystemCppBPLibrary::CloneChildActorAndCmp(AActor *ScrActor, AActor *DesActor, bool OnlySaveGameFlag)
{
verify((ScrActor&&DesActor) || (!ScrActor && !DesActor));
if (!ScrActor||!DesActor)
{
return false;
}
ClonePropertyInfo(ScrActor, DesActor, OnlySaveGameFlag);
auto ScrCmps = GetChildComponent<UActorComponent>(ScrActor);
auto DesCmps = GetChildComponent<UActorComponent>(DesActor);
for (UActorComponent *it : ScrCmps)
{
auto compsName = it->GetName();
for (UActorComponent *it2 : DesCmps)
{
auto compsName2 = it2->GetName();
if (compsName == compsName2)
{
if (Cast<USceneComponent>(it2))
{
if (Cast<UChildActorComponent>(it2))
{
verify(Cast<UChildActorComponent>(it));
CloneChildActorAndCmp(Cast<UChildActorComponent>(it)->GetChildActor(), Cast<UChildActorComponent>(it2)->GetChildActor(), OnlySaveGameFlag);
}
auto SceneIt = Cast<USceneComponent>(it2);
auto TParent = SceneIt->GetAttachParent();
if (Cast<USceneComponent>(it2)->GetAttachParent())ClonePropertyInfo(it, it2, OnlySaveGameFlag);
verify(TParent == SceneIt->GetAttachParent());
//SceneIt->SetRelativeTransform(Cast<USceneComponent>(it)->GetRelativeTransform());
SceneIt->SetAbsolute(Cast<USceneComponent>(it)->IsUsingAbsoluteLocation(), Cast<USceneComponent>(it)->IsUsingAbsoluteRotation(), Cast<USceneComponent>(it)->IsUsingAbsoluteScale());
SceneIt->SetVisibility(false);
SceneIt->SetVisibility(true);
SceneIt->SetVisibility(Cast<USceneComponent>(it)->IsVisible());
}
else
{
ClonePropertyInfo(it, it2, OnlySaveGameFlag);
}
break;
}
}
}
return true;
}
void UNewCAVESystemCppBPLibrary::MoveActorToNewLevel(AActor* InputActor, ULevel* NewLevel)
{
UWorld * World = InputActor->GetWorld();
//World->RemoveActor(InputActor, true);
ULevel * OldLevel = InputActor->GetLevel();
if (OldLevel == NewLevel)
{
UE_LOG(LogTemp, Warning, TEXT("MoveActorToLevel: Actor already exists in the level"));
return;
}
World->RemoveActor(InputActor, true);
InputActor->Rename((const TCHAR *)0, NewLevel); //Set the outer of Actor to NewLevel
NewLevel->Actors.Add(InputActor);
}
void UNewCAVESystemCppBPLibrary::SetActorLoadedOnClient(AActor * InputActor, bool TrueOrFalse)
{
InputActor->bNetLoadOnClient = TrueOrFalse;
}
bool UNewCAVESystemCppBPLibrary::SetLevelSequenceActorDisableCameraCuts(ALevelSequenceActor * LevelSequenceActor, bool bDisable)
{
if (LevelSequenceActor && LevelSequenceActor->GetSequencePlayer())
{
LevelSequenceActor->PlaybackSettings.bDisableCameraCuts = bDisable;
return true;
}
return false;
}
bool UNewCAVESystemCppBPLibrary::IsModuleLoaded(FName ModuleName)
{
FModuleManager& ModuleManager = FModuleManager::Get();
return ModuleManager.IsModuleLoaded(ModuleName);
}
void UNewCAVESystemCppBPLibrary::SetPlayerControllerAutoManageCamera(APlayerController * PC, bool TrueOrFalse)
{
PC->bAutoManageActiveCameraTarget = TrueOrFalse;
}
UClass * UNewCAVESystemCppBPLibrary::LoadClassAsset_Blocking(TSoftClassPtr<UObject> AssetClass)
{
return AssetClass.LoadSynchronous();
}
int32 UNewCAVESystemCppBPLibrary::GetObjectGUID(UObject* obj)
{
return obj->GetUniqueID();
}
UObject * UNewCAVESystemCppBPLibrary::GetObjectByGUID(int32 GUID)
{
if (GUObjectArray.IndexToObject(GUID)&&GUObjectArray.IndexToObject(GUID)->Object&&GUObjectArray.IndexToObject(GUID)->Object->IsValidLowLevel())
{
return static_cast<UObject*>(GUObjectArray.IndexToObject(GUID)->Object);
}
return nullptr;
}
float UNewCAVESystemCppBPLibrary::GetInputAxisValue(AActor * InputActor, const FName InputAxisName)
{
return InputActor->GetInputAxisValue(InputAxisName);
}
float UNewCAVESystemCppBPLibrary::GetInputAxisKeyValue(AActor * InputActor, const FKey InputAxisKey)
{
return InputActor->GetInputAxisKeyValue(InputAxisKey);
}
FVector UNewCAVESystemCppBPLibrary::GetInputVectorAxisValue(AActor * InputActor, const FKey InputAxisKey)
{
return InputActor->GetInputVectorAxisValue(InputAxisKey);
}
void UNewCAVESystemCppBPLibrary::BindAxis(AActor * InputActor, const FName AxisEvent)
{
if (InputActor && InputActor->InputComponent)
{
InputActor->InputComponent->BindAxis(AxisEvent);
}
}
void UNewCAVESystemCppBPLibrary::BindAxisKey(AActor * InputActor, const FKey AxisKey)
{
if (InputActor && InputActor->InputComponent)
{
if (AxisKey.IsAxis1D())
InputActor->InputComponent->BindAxisKey(AxisKey);
}
}
void UNewCAVESystemCppBPLibrary::BindVectorAxisKey(AActor * InputActor, const FKey AxisKey)
{
if (InputActor && InputActor->InputComponent)
{
InputActor->InputComponent->BindVectorAxis(AxisKey);
}
}
void UNewCAVESystemCppBPLibrary::UnbindAllInput(AActor * InputActor)
{
if (InputActor && InputActor->InputComponent)
{
InputActor->InputComponent->ClearActionBindings();
InputActor->InputComponent->AxisKeyBindings.Empty();
}
}
//void UNewCAVESystemCppBPLibrary::SetWidgetComponentTickWhenOffScreen(UWidgetComponent * WComp, bool TrueOrFalse)
//{
// WComp->__PPO__TickWhenOffscreen = TrueOrFalse;
//}
/*
UClass* UNewCAVESystemCppBPLibrary::GetClassByPath(const FName& AssetPath)
{
UClass* CustomClass = LoadClass<AActor>(NULL, *(AssetPath.ToString() + "_C"));
if (CustomClass && CustomClass->IsValidLowLevel())
{
return CustomClass;
}
return nullptr;
}
UCanvasPanel* UNewCAVESystemCppBPLibrary::GetCanvasPanel(UUserWidget* UserWidget)
{
if (!UserWidget)
{
return nullptr;
}
UCanvasPanel* CanvasPanel = Cast<UCanvasPanel>(UserWidget->GetRootWidget());
if (!CanvasPanel)
{
return nullptr;
}
return CanvasPanel;
}
UTexture2D* UNewCAVESystemCppBPLibrary::LoadImageByPath(FString ImagePath)
{
if (!FPaths::FileExists(ImagePath))
{
return FImageUtils::ImportFileAsTexture2D(GetBaseDir() + ImagePath);
}
return FImageUtils::ImportFileAsTexture2D(ImagePath);
}
void UNewCAVESystemCppBPLibrary::SleepGame(float time)
{
FPlatformProcess::Sleep(time);
}
*/
class FSlateUserInputMapping : public FSlateDefaultInputMapping
{
public:
virtual int32 GetUserIndexForController(int32 ControllerId) const override { return -1; }
};
void UNewCAVESystemCppBPLibrary::EnableAllUserMouse()
{
static auto InputMap = MakeShared<FSlateUserInputMapping>();
FSlateApplication::Get().SetInputManager(InputMap);
}
UCameraComponent* UNewCAVESystemCppBPLibrary::GetCurrentCameraFromSequence(UObject* WorldContextObject, ULevelSequencePlayer* InSeqPlayer)
{
if (!InSeqPlayer) return nullptr;
// <20><>ȡ CameraCut <20><><EFBFBD><EFBFBD>
ULevelSequence* LevelSequence = Cast<ULevelSequence>(InSeqPlayer->GetSequence());
if (!LevelSequence) return nullptr;
UMovieSceneCameraCutTrack* CameraCutTrack = Cast<UMovieSceneCameraCutTrack>(LevelSequence->GetMovieScene()->GetCameraCutTrack());
if (!CameraCutTrack) return nullptr;
//FQualifiedFrameTime CurrentTime = MyLevelSequencePlayer->GetCurrentTime(); // <20><>ȡ<EFBFBD><C8A1>ǰʱ<C7B0><CAB1>
//auto CurrentFrame = CurrentTime.Time.FrameNumber*800;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ
// <20><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>֡
FFrameRate TickResolution = LevelSequence->GetMovieScene()->GetTickResolution();
FQualifiedFrameTime QualifiedTime = InSeqPlayer->GetCurrentTime();
FFrameTime TimeInTick = ConvertFrameTime(QualifiedTime.Time, QualifiedTime.Rate, TickResolution);
FFrameNumber CurrentTickFrame = TimeInTick.GetFrame();
// <20><><EFBFBD>ҵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CameraCut <20><>
UCameraComponent* ActiveCamComp = nullptr;
for (UMovieSceneSection* Section : CameraCutTrack->GetAllSections())
{
if (UMovieSceneCameraCutSection* CamSection = Cast<UMovieSceneCameraCutSection>(Section))
{
auto StartFrame = CamSection->GetInclusiveStartFrame();
auto EndFrame = CamSection->GetExclusiveEndFrame();
if (CurrentTickFrame >= StartFrame && CurrentTickFrame < EndFrame)
{
// <20><>ȡ<EFBFBD>󶨵Ķ<F3B6A8B5><C4B6><EFBFBD>
TArray<UObject*> BoundObjs = InSeqPlayer->GetBoundObjects(CamSection->GetCameraBindingID());
for (UObject* Obj : BoundObjs)
{
if (AActor* Actor = Cast<AActor>(Obj))
{
ActiveCamComp = Actor->FindComponentByClass<UCameraComponent>();
}
else if (UCameraComponent* CamComp = Cast<UCameraComponent>(Obj))
{
ActiveCamComp = CamComp;
}
if (ActiveCamComp) break;
}
break;
}
}
}
return ActiveCamComp;
}
/*
bool UNewCAVESystemCppBPLibrary::LoadLevelAsync(const FString & InName, FOnPackageLoaded OnPackageLoaded)
{
//LoadPackageAsync(InName, FLoadPackageAsyncDelegate::CreateLambda([=](const FName& PackageName, UPackage* LoadedPackage, EAsyncLoadingResult::Type Result) {OnPackageLoaded.ExecuteIfBound(); }), 0, PKG_ContainsMap);
//GEngine->AddOnScreenDebugMessage(-1, 100.0f, FColor::Red, FString::Printf(TEXT("Create New World : %s"), *InName));
// Check whether requested map exists, this could be very slow if LevelName is a short package name
FString LongPackageName;
bool bOutSuccess = FPackageName::SearchForPackageOnDisk(InName, &LongPackageName);
if (!bOutSuccess)
{
UE_LOG(LogTemp, Error, TEXT("Map not found"));
return false;
}
LoadPackageAsync(LongPackageName, FLoadPackageAsyncDelegate::CreateLambda([=](const FName& PackageName, UPackage* LoadedPackage, EAsyncLoadingResult::Type Result)
{
//LoadedPackage->AddToRoot();
OnPackageLoaded.ExecuteIfBound();
}), 0, PKG_ContainsMap);
return true;
}
bool UNewCAVESystemCppBPLibrary::CheckPackageIsInMemory(const FString & PackageName)
{
UPackage* WorldPackage = nullptr;
// See if the level is already in memory
WorldPackage = FindPackage(nullptr, *PackageName);
return WorldPackage ? true : false;
}
bool UNewCAVESystemCppBPLibrary::CreateWorldFromPackage(UObject* WorldContextObject, const FString & PackageName)
{
UPackage* WorldPackage = nullptr;
WorldPackage = FindPackage(nullptr, *PackageName);
UWorld* NewWorld = nullptr;
if (WorldPackage)
{
NewWorld = UWorld::CreateWorld(WorldContextObject->GetWorld()->WorldType, true, "UnTitle", WorldPackage, true, ERHIFeatureLevel::SM5);
//NewWorld->InitWorld();
//NewWorld->AddToRoot();
}
return false;
}
bool UNewCAVESystemCppBPLibrary::CheckWorldInPackage(const FString& PackageName)
{
UPackage* WorldPackage = nullptr;
WorldPackage = FindPackage(nullptr, *PackageName);
if (WorldPackage)
{
UWorld *NewWorld = nullptr;
NewWorld = UWorld::FindWorldInPackage(WorldPackage);
if (NewWorld)
{
GEngine->AddOnScreenDebugMessage(-1, 100.0f, FColor::Red, FString::Printf(TEXT("Found World %s in package"), *NewWorld->GetName()));
if (NewWorld->PersistentLevel)
GEngine->AddOnScreenDebugMessage(-1, 100.0f, FColor::Red, FString::Printf(TEXT("Found Level %s in world"), *NewWorld->GetName()));
}
return true;
}
return false;
}
*/