508
1.优化代码,设置get方法:
//FORCEINLINE是UE中的一个宏,用于优化,用在get/set方法之前或者方法体中只有一条return语句
FORCEINLINE UStaticMeshComponent* GetStaticMeshComponent(){return MyStaticMesh;}
FORCEINLINE USpringArmComponent* GetSpringArmComponent(){return MySpringArm;}
2.在CPP中替换上述两个方法
3.加载静态网格、材质文件:
#include "UObject/ConstructorHelpers.h"
//其中的XXX为在content brower中找到对应的网格模型和材质的文件,选中点击右键拷贝他们的文件引用路径
static ConstructorHelpers::FObjectFinder<UStaticMesh>StaticMeshAsset(TEXT("xxx"));
static ConstructorHelpers::FObjectFinder<UMaterialInterface>MaterialAsset(TEXT("xxx"));
if(StaticMeshAsset.Succeeded() && MaterialAsset.Succeeded()){
MyStaticMesh->SetStaticMesh(StaticMeshAsset.Object);
MyStaticMesh->SetMaterial(0,MaterialAsset.Object);
MyStaticMesh->SetWorldScale3D(FVector(0.5f));
}