我是游戏开发方面的新手。通过培训课程开始(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));
}
}我有一个问题,我不能在编辑器中移动到AActor后,将它放在ViewPort中。我读到我为我的演员错过了RootComponent,但我不知道如何添加它(也许我不完全理解演员)。能帮你有我的源代码来解决我的问题吗?这段代码是在训练方面做的。我的目标-增加一个演员,并能够移动和旋转它。
发布于 2015-04-16 15:18:02
请添加这段代码
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);https://stackoverflow.com/questions/24503835
复制相似问题