Unreal中类与组件的关系获取

获得场景里的actor

for (TActorIterator<AStaticMeshActor> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
    AStaticMeshActor *Mesh = *ActorItr;
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(ActorItr->GetName()));
}

获得场景里直接拖到actor上面的actor

TArray<AActor*>aa;
actor->GetAttachedActors(aa);
for (int32 b = 0; b < aa.Num(); b++)
{
    AActor*a = aa[b];  
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(a->GetName()));
}

获得actor上面的component ——通过类型

//这里填什么类型获得的就是什么类型的 component
TArray<UActorComponent*>aa; 
actor->GetComponents(aa);
for (int32 b = 0; b < aa.Num(); b++)
{
    UActorComponent*a = aa[b];
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(a->GetName()));
}

获得actor上面的component ——通过class

actor->GetComponentByClass(UActorComponent::StaticClass());//填你想获得的componet 的类

获得actor上面的component 通过class(所有这个类型的component)——比上面的方法多了一个s

TArray<UActorComponent*> ll( actor->GetComponentsByClass(UActorComponent::StaticClass()));//填你想获得的componet 的类
for (int32 b = 0; b < ll.Num(); b++)
{
    UActorComponent*a = ll[b];
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(a->GetName()));
}

获得actor上面的root component 下面的所有component

TArray<USceneComponent*> My_Children;
actor->GetRootComponent()->GetChildrenComponents(false, My_Children);
for (int32 b = 0; b < My_Children.Num(); b++)
{
    USceneComponent*a = My_Children[b];
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(a->GetName()));
}

获得actor上面的UChildComponent 上面的actor

TArray<AActor*>aa;
actor->GetAllChildActors(aa,true);
for (int32 b = 0; b < aa.Num(); b++)
{
    AActor*a = aa[b];
    UE_LOG(LogTemp, Warning, TEXT("%s"), *(a->GetName()));
}

AActor 类里 有一个Children 属性,这个是服务器用来复制网络消息的,客户端一般用不到

/** Array of Actors whose Owner is this actor */
    UPROPERTY(transient)
    TArray<AActor*> Children;

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值