如何列出ULevelStreaming中的所有参与者?
How to list all of the actors in ULevelStreaming?
我找不到一种方法来列出子关卡(LevelStreaming(中的所有Actor。对于枚举,我尝试使用TActorIterator,但它的构造函数接受对UWorld的引用,它不接受对ULevelStreaming的引用,因为它们都继承自UObject,而ULevelStreaming不继承自UWorld。我可以像这样列出世界上所有的演员:
UWorld* world = GetWorld();
TActorIterator<AActor> Iterator(world, AActor::StaticClass());
for (; Iterator; ++Iterator)
{
AActor* Actor = Cast<AActor>(*Iterator);
GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Yellow, Actor->GetFName().ToString()); //Print name of the Actor
}
这有效,但我只从主地图(持久级别(中获取对象,而且我不知道如何从我添加为 ULevelStream 的其他级别中获取所有 Actor 的列表。 这是我的尝试(不起作用(:
UWorld* world = GetWorld();
auto levels = world->GetStreamingLevels();
for (auto level : levels) {
ULevelStreaming* currentLevel = Cast<ULevelStreaming>(level);
TActorIterator<AActor> It(currentLevel, AActor::StaticClass()); //Here is compiler error with TActorIterator's constructor
for (; It; ++It)
{
AActor* Actor = Cast<AActor>(*It);
GEngine->AddOnScreenDebugMessage(-1, 30.f, FColor::Yellow, Actor->GetFName().ToString());
}
}
首先 - 必须加载级别。然后你可以使用GetLoadedLevel来获取ULevel。ULevel已经有了Actor- 所有 actor 的数组
UWorld* world = GetWorld();
auto StreamingLevels = world->GetStreamingLevels();
for (UStreamingLevel* StreamingLevel : StreamingLevels ) {
ULevel* level = StreamingLevel->GetLoadedLevel();
if(!level)
continue;
for (AActor* Actor : level->Actors)
{
// Actor
}
}
相关文章:
- 递归列出所有目录中的C++与Python与Ruby的性能
- 函数何时会在c++中包含stack_Unwind_Resume调用
- Python中的for循环与C++有何不同
- 如何在CPP的给定目录中列出UTF编码的文件名?
- 在C++中释放内存期间,迭代器与指针有何不同
- 如何删除列出的"QGraphicsPathItem"对象以控制进程内存使用情况?
- 从所有列出的文件和子目录中更改目录
- 使用类在C++中存储和列出变量/方法是否是一种好的做法
- 标准对此指向成员函数类型模板参数有何说明?是我的代码有误,还是 MSVS 16.6 有问题?
- 如何在组合框中列出所有可用的 VCL 样式,并在组合框更改事件中应用该样式C++生成器?
- 有没有办法列出所有共享内存对象的名称?
- Qt C++11 字符串通过子字符串比较列出交集
- 列出埃拉托色尼的筛子
- 如何列出ULevelStreaming中的所有参与者?
- 类中的 C++ int 被设置为值,似乎不知从何而来
- -fvisibility-inline-hidden 与 gcc 中的 -fvisibility=hidden 有何不同
- Boost.Python 列出了所有公开的类和属性
- 使用柯南打包时如何避免列出两次依赖?
- 为什么在功能内擦除元素后不列出更新?
- 列出目录 WinAPI 中的文件