2

我是游戏开发的新手。通过培训课程入门(https://docs.unrealengine.com/latest/INT/Programming/QuickStart/7/index.html)我创建了一个类 AMyActorTest 扩展 AActor:

#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));
    }

}

我有一个问题,在将编辑器放入 ViewPort 后,我​​无法在编辑器中移动到 AActor。我读到我的 Actor 缺少 RootComponent,但我不明白如何添加它(也许我不完全理解演员)。可以帮助您获得我的源代码来解决我的问题吗?这段代码是在训练方面做的。我的目标 - 添加一个演员并能够移动和旋转它。

4

1 回答 1

1

请添加此代码

RootComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("Root"));

给你的构造函数。就这样。如果您想添加其他组件,可以使用类似的代码(此示例创建UInstancedStaticMeshComponent

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);
于 2015-04-16T15:18:02.447 回答