Unreal引擎自带的有用的工具函数和小Tips,持续更新中

Unreal引擎自带的有用的工具函数,持续更新中


1、计算三角形法线、面积等的函数
Epic Games\UE_x.x\Engine\Source\Runtime\GeometryCore\Public\VectorUtil.h
2、计算FMeshDescription的切线、法线和简单UV等的函数
Epic Games\UE_x.x\Engine\Source\Runtime\StaticMeshDescription\Public\StaticMeshOperations.h
3、通过耳切法计算2D、3D多边形顶点索引
Epic Games\UE_x.x\Engine\Source\Runtime\GeometryCore\Public\CompGeomPolygonTriangulation.h
4、凸包算法
Epic Games\UE_x.x\Engine\Source\Runtime\Core\Public\Math\ConvexHull2d.h

Tips:
1、在C++中,当要创建拥有ExposeOnSpawn的属性的Actor时,写法如下:

		FTransform transform;
		FActorSpawnParameters spawnInfo;
		spawnInfo.bDeferConstruction = true;//构造函数延迟执行
		if (info.Style == "Solid01")
		{
			AActor* actor = _world->SpawnActor(AActor::StaticClass(), transform, spawnInfo);
		if (IsValid(actor)) {
			actor->Info = info;//Info为ExposeOnSpawen=true的属性
			actor->FinishSpawning(transform);//手动执行创建
		}

2、在C++中,获取蓝图Actor的Class:

FTransform transform;
FActorSpawnParameters spawnInfo;
spawnInfo.bDeferConstruction = true;
APolymeshActor* actor = nullptr;
if (info.Style == "Solid01")
{
//获取蓝图Actor资源的Class,“/Script/Engine.Blueprint'/TestPlugin/Polymesh/BP_Polymesh_Solid01.BP_Polymesh_Solid01‘”是Copy Reference后拿到的值,要在最后一个'前面加上_C
	UClass* solid01Class = LoadClass(this, TEXT("/Script/Engine.Blueprint'/TestPlugin/Polymesh/BP_Polymesh_Solid01.BP_Polymesh_Solid01_C'"));
	actor = _world->SpawnActor(solid01Class, transform, spawnInfo);
}
else {
	actor = _world->SpawnActor(APolymeshActor::StaticClass(), transform, spawnInfo);
}
if (IsValid(actor)) {
	actor->Info = info;
	actor->FinishSpawning(transform);
}

3、在C++中,UStaticMesh有一个SetMaterial方法,但是这个方法仅是编辑器状态下可用的,如果想程序在打包后还能动态修改材质,应该使用UStaticMeshComponent的SetMaterial方法。

你可能感兴趣的:(unreal)