Unreal engine4 如何在虚幻编辑器中添加演员并将其移动?
我是游戏开发新手。通过培训课程开始()我创建了一个类AMyActorTest extended AActor:Unreal engine4 如何在虚幻编辑器中添加演员并将其移动?,unreal-engine4,Unreal Engine4,我是游戏开发新手。通过培训课程开始()我创建了一个类AMyActorTest extended AActor: #include "TestUProject.h" #include "MyActorTest.h" AMyActorTest::AMyActorTest(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP) { MyNumber = 12; } void AMyActorT
#include "TestUProject.h"
#include "MyActorTest.h"
AMyActorTest::AMyActorTest(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
MyNumber = 12;
}
void AMyActorTest::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Hello World!"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, FString::FromInt(MyNumber));
}
}
我有一个问题,在将编辑器放置到视口后,无法将其移动到AActor。我读到我的Actor缺少RootComponent,但我不知道如何添加它(也许我不完全理解actors)。能帮你用我的源代码解决我的问题吗?该代码在培训方面做得很好。
我的目标-添加一个演员,并能够移动和旋转它 请添加此代码
RootComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("Root"));
RootComponent=PCIP.CreateDefaultSubobject(此为文本(“根”);
给你的构造器。这就是全部。如果要添加其他组件,可以使用类似的代码(此示例创建UInstancedStaticMeshComponent:
UInstancedStaticMeshComponent*instancedComp=PCIP.CreateDefaultSubobject(RootComponent,TEXT(“subShinstanced”);
instancedComp->AttachTo(RootComponent);//这很重要!
//此部分特定于此组件
//(尽管这些都是其他类型的根子项所共有的)
InstanceComp->SetStaticMesh(网格);
InstanceComp->SetMaterial(0,物料);
InstanceComp->Bownernose=false;
InstanceComp->bCastDynamicShadow=false;
InstanceComp->CastShadow=false;
InstanceComp->SetHiddenInGame(假);
InstanceComp->SetMobility(EComponentMobility::静态);
UInstancedStaticMeshComponent* instancedComp = PCIP.CreateDefaultSubobject<UInstancedStaticMeshComponent>(RootComponent, TEXT("SubMeshInstanced"));
instancedComp->AttachTo(RootComponent); // this is important!
// this part is specific to this component
// (although all are common to other types of your Root subitems)
instancedComp->SetStaticMesh(mesh);
instancedComp->SetMaterial(0, material);
instancedComp->bOwnerNoSee = false;
instancedComp->bCastDynamicShadow = false;
instancedComp->CastShadow = false;
instancedComp->SetHiddenInGame(false);
instancedComp->SetMobility(EComponentMobility::Static);