记录UE4,Component的应用的一些问题.

 

Q. 在UE4中往Actor/Pawn 中动态创建 Component与ChildActor 

Note:旧版本的UE4 的Attach 和12.13版本有些不一样

创建Component:

UCpp_MyComponent* temp_imageCom = NewObject<UCpp_MyComponent>(this, UCpp_MyComponent::StaticClass());
temp_imageCom->RegisterComponent();
temp_imageCom->AttachToComponent(pParentComponent, FAttachmentTransformRules::KeepRelativeTransform);

 

创建Actor Component:

仅多了一步SetChildActorClass

auto temp_childActorComponent = NewObject<UChildActorComponent>(this, UChildActorComponent::StaticClass());
temp_imageCom->RegisterComponent();
temp_childActorComponent->SetChildActorClass(*MyActorClass);
temp_imageCom->AttachToComponent(pParentComponent, FAttachmentTransformRules::KeepRelativeTransform);

 

删除函数:(命名真是迷)

DetachRootComponentFromParent

例如:

 Note:慎用此UChildActorComponent的动态生成方式

   父类Actor 的SetActorEnableCollision 方法,是不会影响 UChildActorComponent 的 GetChildActor()的,但是最搞笑的是当你调用父类Actor 的 SetActorHiddenGame 却会隐藏掉 UChildActorComponent 的 GetChildActor()。

   如果想通过UChildActorComponent的GetChildActor()对Actor进行Transform 操作的话不能采用Relative, 必须采用World 或者直接Transform Actor 的 ActorComponent

相关文章:

  • 2021-07-28
  • 2021-12-23
  • 2021-07-19
  • 2022-12-23
  • 2021-11-03
  • 2021-09-28
  • 2022-01-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2021-05-27
  • 2022-02-21
  • 2022-12-23
相关资源
相似解决方案