UE5 C++学习笔记
Log
- Log类型ELogVerbosity
- Log
- Warning
- Error
- All
- UE_LOG
- 如何使用UE_LOG
1
2
3
4
5
6
7
8//单个文件,定义自己的Log类型
DEFINE_LOG_CATEGORY_STATIC(CategoryName,Log,All);
//全局文件定义,需要include头文件
// xxx.h 头文件声明一个Category为extern,避免多个文件使用此头文件时重复声明
DECLARE_LOG_CATEGORY_EXTERN(CategoryName, Log, All)
// xxx.cpp 源文件定义该Category,全局仅需一份
DEFINE_LOG_CATEGORY(CategoryName)
- 如何使用UE_LOG
- UE_LOG格式化输出
1
2
3UE_LOG(LogTemp, Warning, TEXT("init"));
UE_LOG(LogTemp, Log, TEXT("Key : %d Value: %s"), Test.key, Test.Value);
GEngine->AddOnScreenDebugMessage(0, 2.0f, FColor::Yellow, TEXT("init"));
Debug
命名规范
- UE4 C++基础 - 编码规范
- T 表示模板类
- U 表示类继承自 UObject
- A 表示类继承自 AActor
- S 表示类继承自 SWidget
- I 表示抽象接口类
- E 表示枚举
- b 表示布尔值
- F 表示其他不满足上述规则的类
Get
- GEngine->getXXX()
- GEditor->getXXX()
- GEditor->GetEditorWorldContext().World()
Spawn
TArray TMap
Reflection
- UE4属性反射小结
- FindField
(Target->GetClass(), VarName) - FloatProp->GetPropertyValue_InContainer(Target)
- FindField
- UE4 C++ 利用反射获取到类、类的成员
- UCLASS
- UPROPERTY
- EditAnywhere
- VisibleAnywhere
- BlueprintReadWrite
- Category = “Test”
- Meta = (key=value, key=value, …)
- API Doc
- UFUNCTION
- BlueprintCallable
- CallInEditor
- API Doc
- UENUM
- 一文搞懂StaticClass、GetClass和ClassDefaultObject
- 一文搞懂NativeClass、GeneratedClass、BlueprintClass、ParentClass
- UE4 从UProperty到FProperty
- 在UE4中,通过特殊的宏,将所需要反射的数据进行标记,从而自动的生成供运行时查询的信息
- FindObject(UClass)
- NewObject(UClass)
- 从4.25开始,此UProperty已完全更改为FProperty。 前缀“F”说明其不再继承UObject
- 在UE4中,通过特殊的宏,将所需要反射的数据进行标记,从而自动的生成供运行时查询的信息
Module | Plugin
Engine Module
- Core
- 基础数据类型:int32 FString float
- 数学函数,结构体:FMath FVector
- 容器:TArray TList TMap
- CoreUObject
- 基础类:UObject UClass UProperty UPackage
- 对象内存分配函数:ConstuctObject FindObject Cast
- Engine
- 场景对象、组件:AActor APawn UActorComponent
- 关卡、世界、玩家:UWorld ULevel UPlayer
- 模型、纹理、材质:UTexture UMaterial UStaticMesh
- Slate
UObject
- [UE4 UObject] 对象概念
- UClass::GetDefaultObject() 获取到的为类的 CDO 对象
- CDO 对象的主要作用就是用于为类提供默认值
- UObject::GetOuter() 获取自己的 Outer 对象
- 一个对象的 Outer 称为这个对象的父对象,而自己就称为 Outer 对象的子对象
- 仅能在 UObject 的 Native 构造函数中,调用自己的 UObject::CreateDefaultSubobject() 为自己创建默认子对象
- UPackage 对象对应于磁盘上的一个 .uasset 资源文件,或全局临时包
- 《InsideUE4》目录
- 《InsideUE4》UObject(一)开篇
- 《InsideUE4》GamePlay架构(一)Actor和Component
- 使UObject能够进行Tick
Editor
String
FString 属于可变字符串
FName FText 属于不可变字符串,创建后内容不能改变
FName 不区分大小写,主要用于标识资源路径,它的优点就是查找和访问速度快
FString转换至FName时会丢失原始字符串的大小写信息
FText 主要用于文本本地化
格式化
- FString::Printf(TEXT(“FormatString:\n%s%s%s”), *A, *B, *Plus);
Thread
Pointer
GC
Tools
Third Party C++ Library
- UnrealMeshProcessingTools
- Interactive Mesh Processing with libigl in Unreal Engine 4.24
- UE4链接第三方库的具体使用和演示
- UE4链接第三方库(lib和dll)
- UE4中使用第三方库
- 修改UE源码之配置第三方库
- Engine\Source\ThirdParty
- add
- PublicAdditionalLibraries.Add(XXX + “cublas.lib”)
- PublicDelayLoadDLLs.Add(“cublas64_11.dll”)
- RuntimeDependencies.Add(XXX + “bin/“ + “cublas64_11.dll”)
- PublicDefinitions.Add(“NV_CUDA=1”)
- using
- AddEngineThirdPartyPrivateStaticDependencies(Target, “CUDA_V11”)
- add
- Engine\Source\ThirdParty
Summary
信息是一种能量,只有足够的信息,才能达到质变(Epic大钊)
Build Cmd
UE项目工程
1 |
|
UE源码工程
1 |
|
RunUAT编译
- unreal-automation-tool
- RunUAT.bat -List
- RunUAT.bat BuildGame -Help
- UE4中使用Cmd升级插件版本
1
RunUAT.bat BuildPlugin -plugin="D:\xxx.uplugin" -package="D:\xxx"
- UE4 Slate独立引用程序
- 应用程序依赖特定文件结构和Shader着色器
- 建议直接打包运行器,作为已经配置完成的一栏
- RunUAT脚本工具打包
- dotnet工具
- AutomationTool
- BuildGraph
Reference
VT
Geometry
Landscape
FHoudiniLandscapeTranslator::ImportLandscapeData => SetMaskLayer
FHoudiniLandscapeTranslator::BackupLandscapeToImageFiles => ExportHeightLayer
FHoudiniLandscapeTranslator::CreateOrUpdateLandscapeLayerData
- ULandscapeLayerInfoObject* LayerInfo = GetLandscapeLayerInfoForLayer()
- LayerInfo = FindOrCreateLandscapeLayerInfoObject()
FLandscapeLayer
- OnGetImportLayerCreateMenu //GUI Create
- OnImportLayerCreateClicked
- OnGetImportLayerCreateMenu //GUI Create
Process
- ULandscapeLayerInfoObject => create layerInfo package
- Switch Material
- Import Layer from texture
- Find or Create layerInfo
- set layerInfo
- FHoudiniLandscapeTranslator::OutputLandscape_GenerateTile
- TArray
LayerInfos; - for (const auto& ImportLayerInfo : LayerInfos)
- LandscapeActor->EditorLayerSettings.Add(FLandscapeEditorLayerSettings(ImportLayerInfo.LayerInfo))
- create layerInfo
- FHoudiniLandscapeTranslator::CreateOrUpdateLandscapeLayerData
- FHoudiniLandscapeTranslator::FindOrCreateLandscapeLayerInfoObject
ALandscapeProxy
- ULandscapeInfo *LandscapeInfo = Landscape->GetLandscapeInfo();
ALandscape : public ALandscapeProxy
- Landscape = World->SpawnActor
() - Landscape->Import()
- ULandscapeInfo *LandscapeInfo = Landscape->GetLandscapeInfo();
- LandscapeInfo->UpdateLayerInfoMap(Landscape);
- Landscape->RegisterAllComponents();
- Landscape = World->SpawnActor
Engine\Source\Editor\LandscapeEditor\Private\LandscapeEditorDetailCustomization_ImportLayers.cpp
Engine\Source\Editor\LandscapeEditor\Private\LandscapeEditorDetailCustomization_ImportExport.cpp
Engine\Source\Editor\LandscapeEditor\Private\LandscapeEditorDetailCustomization_TargetLayers.cpp
- OnTargetLayerDeleteClicked
The import size (505×505) does not match the current Landscape extent (0×0), if you continue it will be padded/clipped to fit
Engine\Source\Editor\LandscapeEditor\Private\LandscapeEdMode.cpp
- FEdModeLandscape::ChangeComponentSetting
- TMap<FGuid, TArray
> HeightDataPerLayers; - TMap<FGuid, TArray
> ImportMaterialLayerInfosPerLayers; - auto ExtractHeightmapWeightmapContent = [&](TArray
& OutHeightData, TArray & OutImportMaterialLayerInfos) - if (HasLandscapeLayersContent()) // edit layers
- ExtractHeightmapWeightmapContent(HeightData, ImportMaterialLayerInfos);
- ImportMaterialLayerInfosPerLayers.Add(FGuid(), MoveTemp(ImportMaterialLayerInfos)); // add data
- NewLandscape->Import(FGuid::NewGuid(), NewMinX, NewMinY, NewMaxX, NewMaxY, NumSubsections, SubsectionSizeQuads, HeightDataPerLayers, *OldLandscape->ReimportHeightmapFilePath, ImportMaterialLayerInfosPerLayers, ELandscapeImportAlphamapType::Additive, LandscapeLayers);
- Import // create new landscape components
- Import(const FGuid& InGuid, int32 InMinX, int32 InMinY, int32 InMaxX, int32 InMaxY, int32 InNumSubsections, int32 InSubsectionSizeQuads, const TMap<FGuid, TArray
>& InImportHeightData, const TCHAR* const InHeightmapFileName, const TMap<FGuid, TArray >& InImportMaterialLayerInfos, ELandscapeImportAlphamapType InImportMaterialLayerType, const TArray * InImportLayers = nullptr); - const TMap<FGuid, TArray
>& InImportMaterialLayerInfos - ALandscapeProxy::Import
- Source\Runtime\Landscape\Private\LandscapeEdit.cpp
- Import(const FGuid& InGuid, int32 InMinX, int32 InMinY, int32 InMaxX, int32 InMaxY, int32 InNumSubsections, int32 InSubsectionSizeQuads, const TMap<FGuid, TArray
- Import // Houdini Engine Import Method
- FHoudiniLandscapeTranslator::UpdateLandscapeMaterialLayers(ALandscape* InLandscape,const TArray
& LayerInfos)
- FHoudiniLandscapeTranslator::UpdateLandscapeMaterialLayers(ALandscape* InLandscape,const TArray
- TMap<FGuid, TArray
- FEdModeLandscape::ChangeComponentSetting
Foliage || Landscape
- FoliageType
- LandscapeLayers
- Source\Editor\FoliageEdit\Private\FoliageEdMode.cpp
- GetMaxHitWeight()
- ULandscapeComponent* HitLandscape
- float HitWeight = HitLandscape->GetLayerWeightAtLocation(Location,LayerName,LayerCache)
- GetMaxHitWeight()