UE4笔记-Component相关问题记录
记录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
本文原创,不定时更新
可以随意转载到任何网站
~但是~ 转载也要按“基本法”
请注明原文出处和作者

浙公网安备 33010602011771号