【UE4 C++】 获取Actor、Controller、Pawn、Character
获取 Actor
TActorIterator 遍历
可以用于遍历 Actor,也可以用于遍历 Component
for (TActorIterator<AStaticMeshActor> ActorIter(GetWorld()); ActorIter; ++ActorIter)
{
UKismetSystemLibrary::PrintString(GetWorld(), FString::Printf(TEXT("%s"), *ActorIter->GetName()));
}
UKismetSystemLibrary::GetAllActorsOfClass
Syntax
static void GetAllActorsOfClass(const UObject* WorldContextObject, TSubclassOf<AActor> ActorClass, TArray<AActor*>& OutActors);
代码实现
TArray<AActor*> OutActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AStaticMeshActor::StaticClass(), OutActors);
for (AActor* actor : OutActors)
{
UKismetSystemLibrary::PrintString(GetWorld(), actor->GetName());
}
UKismetSystemLibrary::GetAllActorsWithTag
Syntax
static void GetAllActorsWithTag(const UObject* WorldContextObject, FName Tag, TArray<AActor*>& OutActors);
UKismetSystemLibrary::GetAllActorsWithInterface
Syntax
static void GetAllActorsWithInterface(const UObject* WorldContextObject, TSubclassOf<UInterface> Interface, TArray<AActor*>& OutActors);
获取 Controller
可配合 Cast 转换成对应的 Controller
UKismetSystemLibrary::GetPlayerController
Syntax
static class APlayerController* GetPlayerController(const UObject* WorldContextObject, int32 PlayerIndex);
代码实现
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
UWorld::GetFirstPlayerController
代码实现
APlayerController* playerController = GetWorld()->GetFirstPlayerController();
获取 Pawn
UKismetSystemLibrary::GetPlayerPawn
代码实现
APawn* myPawn = Cast<ADrone>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
GetPawn
代码实现
APawn* myPawn = GetWorld()->GetFirstPlayerController()->GetPawn();
获取 Character
UGameplayStatics::GetPlayerCharacter
代码实现
ACharacter* myPawn = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
GetCharacter
代码实现
ACharacter* myPawn = GetWorld()->GetFirstPlayerController()->GetCharacter();
【UE4 C++】 获取Actor、Controller、Pawn、Character的更多相关文章
- 【转载】 [unreal4入门系列之七] UE4中的Actor类和Pawn类
原文地址: http://www.52vr.com/article-558-1.html 现在我们开始进入UE4的代码开发工作.首先,UE4的类框架是非常庞大的,看起来有点让人措手不及.不过正因为UE ...
- UE4 中在 Actor 中动态 Create Component 与ChildActor 的 小笔记
Note:旧版本的UE4 的Attach 和12.13版本有些不一样 创建Component: UCpp_MyComponent* temp_imageCom = NewObject<UCpp_ ...
- Yii里获取当前controller和action的id
Yii里获取当前controller和action的id 在控制器里$name = $this->getId(); // controller$name = $action->id; ...
- spring mvc DispatcherServlet详解之一--request通过HandlerMaping获取控制器Controller过程
整个spring mvc的架构如下图所示: 现在来讲解DispatcherServletDispatcherServlet的第一步:获取控制器. HandlerMapping HandlerMappi ...
- token获取在controller层中
集合判断是否为空 注意:token获取在controller层中,token中存的所有数据都要在controller中获取 在自己的接口里调用别的接口需要判断一下返回值是否为空
- Asp.Net MVC 获取当前 Controller Action Area
获取控制器名称: ViewContext.RouteData.Values["controller"].ToString(); 获取Action名称: ViewContext.Ro ...
- C# 通过反射获取MVC Controller里的类名,方法名,参数列表,返回值类型,Description描述,自定义Attribute
需要反射的DLL里的一个类: namespace ElegantWM.WebUI.Areas.Admin.Controllers { [Description("功能模块管理")] ...
- ios 自定义cell类中获取当前controller push
有时候在自定义cell的过程中,当cell中又button的时候,把button的点击时间写在cell中的时候,需要获取到cell的父视图控制器然后push,可以自建一个类,命名为: GetCurre ...
- MVC获取当前Controller/Action名称
1.视图中获取: var actionName=ViewContext.RouteData.Values["action"].ToString().ToLower(); var c ...
随机推荐
- 窗口函数至排序——SQLServer2012可高用
常用到的窗口函数 工作中要常对数据进行分析,分析前要对原始数据中找到想要的格式,数据原本存储的格式不一定时我们想要的,要在基础上进行一定的处理,下面介绍的几种方式是常用的数据排序的集中方式,包含 排名 ...
- 快速模式第三包:quick_inR1_outI2()
快速模式第三包:quick_inR1_outI2() 文章目录 快速模式第三包:quick_inR1_outI2() 1. 序言 2. quick_inR1_outI2()的处理流程 3. 快速模式第 ...
- vue实现拖动div元素
html: <div id="app1"> <div v-drag class="drag"></div> <div ...
- JAVA安全基础之反射
JAVA安全基础之反射 在JAVA安全中,反射是一个经常使用的技术,所以熟悉使用反射是非常必要的.下面就简单的讲下JAVA的反射的用法 什么是反射 每个类都有对应的Class类对象,该Class类对象 ...
- 搭建http文件服务器 - python3使用http.server搭建http文件服务器
适用场景 只要有python3就可以,windows系统cmd窗口直接敲命令,Linux系统,直接敲命令 step-1 cd cd 到需要搭建服务器的目录 step-2 http.server pyt ...
- centos7 发送邮件
yum install sendmail mailx sharutils mutt libreport-plugin-mailx -y yum update libreport-plugin-mail ...
- 定要过python二级 选择题第5套
1. 2.. 3. https://zhidao.baidu.com/question/1952133724016713828.html 4. 5. 6. 7. 8. 9. 10. 11.
- CF786C-Till I Collapse【树状数组倍增,优先队列】
正题 题目链接:https://www.luogu.com.cn/problem/CF786C 题目大意 给出一个长度为\(n\)的序列. 对于每个\(k\in[1,n]\)求将\(n\)分成最少的段 ...
- P3307-[SDOI2013]项链【Burnside引理,莫比乌斯反演,特征方程】
正题 题目链接:https://www.luogu.com.cn/problem/P3307 题目大意 \(n\)个珠子的一个环形项链,每个珠子有三个\(1\sim k\)的整数. 两个珠子不同当且仅 ...
- P4451-[国家集训队]整数的lqp拆分【生成函数,特征方程】
正题 题目链接:https://www.luogu.com.cn/problem/P4451 题目大意 给出\(n\),对于所有满足\(\sum_{i=1}^ma_i=n\)且\(\forall a_ ...