월드 내 모든 액터 가져오기
UWorld* CurrentWorld = GetWorld();
for (const auto& Entry : FActorRange(CurrentWorld))
{
UE_LOG(LogTemp, Warning, TEXT("Actor : %s"), *Entry->GetName());
TArray<UObject* > Components;
Entry->GetDefaultSubobjects(Components);
for (const auto& CEntry : Components)
{
UE_LOG(LogTemp, Warning, TEXT(" -- Component : %s"), *CEntry->GetName());
}
}
원하는 타입의 액터만 선별하여 가져오기
for (TActorIterator<AStaticMeshActor> It(CurrentWorld); It; ++It)
{
UE_LOG(LogTemp, Warning, TEXT("StaticMesh Actor : %s"), *It->GetName());
}
- 월드에서 StaticMesh만 뽑아낸 예시이다.
현재 월드에 로딩된 특정 언리얼 오브젝트를 가져오기
WebConnection->Host = TEXT("localhost");
WebConnectionNew->Host = TEXT("127.0.0.1");
for (TObjectIterator<UWebConnection> It; It; ++It)
{
UWebConnection* Conn = *It;
UE_LOG(LogTemp, Warning, TEXT("WebConnection Object Host : %s"), *Conn->Host);
}
- 액터를 포함해 현재 월드에 로딩된 모든 언리얼 오브젝트를 가져온다.
Serialize
WebConnection->Host = TEXT("127.0.0.7");
WebConnection->URI = TEXT("/");
if (UPackage::SavePackage(NewPackage, WebConnection, RF_Standalone, *FileName))
{
UPackage* SavedPackage = ::LoadPackage(NULL, *FileName, LOAD_None);
TArray<UObject*> ObjectsInPackage;
GetObjectsWithOuter(SavedPackage, ObjectsInPackage, false);
for (const auto& EachObject : ObjectsInPackage)
{
UWebConnection* WebConnectionFromFile = Cast<UWebConnection>(EachObject);
if (WebConnectionFromFile)
{
UE_LOG(LogTemp, Warning, TEXT("WebConnection From File : Host %s , URI %s"),
*WebConnectionFromFile->Host, *WebConnectionFromFile->URI);
}
}
}