1. Component基本介绍 2. 组件创建的方式: 3. 其他 引用: 一. 概览 UE的Gameplay是一个系统,里面包括很多的类,用于方便我们快速搭建一个项目。所有类之中,除了UObject,Actor和Component是相对基础的存在。Actor是一个容器,包含了不同功能的Components,如USceneComponent,保证了Actor有了Location,Rotation和Scale,可以...
// Called when the game startsvoidUMySceneComponent::BeginPlay(){Super::BeginPlay();// 获取组件所属的ActorAActor*OwnerActor=GetOwner();if(OwnerActor){// 获取当前Actor的位置FVector CurrentLocation=OwnerActor->GetActorLocation();// 设置递增或递减方向OriginalZ=CurrentLocation.Z;}}// Called every...
voidAMyTest::BeginPlay(){Super::BeginPlay();// 创建静态网格体if(SM!=nullptr){FTransform Transform=UKismetMathLibrary::MakeTransform(FVector(0.0,0.0,0.0),FRotator(0.0,0.0,0.0),FVector(1.0,1.0,1.0));UActorComponent*AC=AddComponentByClass(UStaticMeshComponent::StaticClass(),false,Transform,false)...
voidAMyTest::BeginPlay(){Super::BeginPlay();// 增加子Actorif(ActorC!=nullptr){FTransform Transform=UKismetMathLibrary::MakeTransform(FVector(0.0,0.0,0.0),FRotator(0.0,0.0,0.0),FVector(1.0,1.0,1.0));UActorComponent*AC=AddComponentByClass(UChildActorComponent::StaticClass(),false,TF,false);AC-...
在打开的窗口中选择Actor,点击Next 在弹出的窗口Name输入类名(创建的.h和.cpp文件也是这个名称),在Path中选择保存路径,点击Create后会打开IDE 默认会有三个方法,构造函数;BeginPlay(),在游戏开始运行时执行,Tick(),在游戏运行时每帧执行 创建Actor Component类 ...
组件(Component)是一种可以添加到Actor的功能。 将组件添加到Actor时,Actor可以使用组件提供的功能。例如: 点光源组件将使Actor像点光源一样发光。 旋转移动组件将使Actor转动。 音频组件将使Actor能够播放音效。 组件必须连接到Actor,不能独自存在。 Pawn
请注意,这个示例假设你已经有一个有效的UWorld指针,并且想要查找的组件类是通过TSubclassOf<UActorComponent>类型指定的。如果你想要查找特定类型的组件(例如USphereComponent),你可以将TSubclassOf<UActorComponent>替换为具体的组件类类型(例如USphereComponent::StaticClass())。
1.3 Actor 生成的性能消耗 接下来我们使用对象池子系统插件中的 BP_PerformanceTest 来测试一下生成过程中各个函数的性能消耗,测试中生成的是一个只有一个 StaticMeshComponent 的 Actor, 每 Tick 生成 100 个该对象。简化 SpawnActor 的流程到 ActorSpawnPerformanceTest::SpawnActors 中,然后每 Tick 生成固定数量的...
在创建时候也会批量执行SpawnDataInitalizer,这里就会在场景里对应的位置上Spawn出Actor,当然前提是Component上要有Actor组件,也就是下面这个Fragment。 这个fragment组件可以看到继承FObjectWrapper Fragment,这个基类其实就是把ECS和UE原本的UObject关联起来的桥梁,UObject的指针会保存在Fragment上面,这样ECS就可以使用Actor了...
在GF框架中,AddComponents是一个频繁使用的功能,它允许在游戏运行时为Actor添加组件。了解其工作原理对于有效使用GF框架至关重要。通过加载流程的理解,我们能够更好地诊断和解决可能出现的问题。AddComponents的作用机制主要在UGameFrameworkComponentManager中实现,此组件继承自GameInstanceSubsystem,仅在游戏运行...