0
点赞
收藏
分享

微信扫一扫

UE4入门 1 如何在空项目中创建Actor并显示在游戏中 C++



新建一个空的项目 只有桌子椅子那个

然后新建一个Actor类

在h文件里面写一个UPROPERTY(Category="Sphere",BlueprintReadOnly)//这里面有好多参数。。可以百度看看

下一行class USphereComponent*Sphere;再一个UPROPERTY 然后是一个class UStaticMeshComponent*SphereMesh

在构造函数里面 处理USphere

createDefaultObject <USphereComponent>(TEXT("RootComponent"));

init一下半径。

还有一个collisionprofilename好像是这个,写成TEXT(”NoCollision”);

RootComponent=USphereComponent;

接着处理一下SphereMesh

还是createdefaultobject

SphereMesh->AttachTo(RootComponent);

constructHelper::FindObject<UStaticMesh>mesh(TEXT("path"));//这里可以去UE4里面。在左下角那里面找到Mesh这类资源 右键点击copyreference贴进TEXT去就行了

if( mesh.succeesed)

{

SphereMesh->setStaticMesh(mesh.object);

init一下位置

}

这个构造函数就弄完了。接着创建一个PlayerController类

先去GameMode类

加在构造函数里

PlayerControllerClass=AMyplayerController::StaticClass();

然后再在AMyplayerController里面重写BeginPlay()

GetWorld()->SpawnActor<AMyPlayer>(AMyplayer,location,rotation))

这样就可以生成一个物体在游戏里了。。具体形状还是看你绑定的网格是什么形状

呃。上面大多数是伪代码。。接口长的差不多。。

嗯 就是酱紫

举报

相关推荐

0 条评论