UE4——查找指定类型或名称的Actor对象

查找名称Target,类型Actor的对象。并在屏幕中显示结果


额外的引用:

#include <EngineGlobals.h>
#include <Runtime/Engine/Classes/Engine/Engine.h>
#include <Runtime/Engine/Public/EngineUtils.h>
#include <Runtime/Engine/Classes/Engine/StaticMeshActor.h>

实现代码:

TActorIterator<AActor> actorItr = TActorIterator<AActor>(GetWorld());
for (actorItr; actorItr; ++actorItr) {
	if (actorItr) {
		if (actorItr->GetName() == "Target") {
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("target is found"));
		}
		else {
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("not found"));
		}
	}
}


posted on 2017-10-25 15:52  仗帅闯江湖  阅读(1253)  评论(0编辑  收藏  举报

导航