坐标系
- unreal: x 前,y 右, z 上
编程入门
- https://docs.unrealengine.com/en-US/Programming/QuickStart/index.html
- https://docs.unrealengine.com/en-US/Programming/Introduction/index.html
- https://unrealcpp.com/line-trace-on-tick
- https://forums.unrealengine.com/community/community-content-tools-and-tutorials/101-victor-s-use-system-tutorial?43-Victor-s-Use-System-Tutorial=
Visual Studio Code
用 code 替换 vc 效果不错
- https://easycomplex-tech.com/blog/Usage-UE4-VScode/
- 在 code 中安装以下插件:C/C++, UnrealEngine 4 Snippets, vscode-epics
- 使用 Visual Studio Installer 安装 Visual C++ build tools 和 .Net Core build tools
- 修改 ue4 的设置: Editor Preferences - General - Source Code - Source Code Editor: Visual Studio Code
- 重启 unreal editor,File 菜单中选择 Generate / Refresh Visual Studio Code Project
- 编译时,在 vscode 中按 ctrl+shift+b,选择 win64 development editor build
- 修改 .vscode/c_cpp_properties.json,添加 "${workspaceFolder}/Intermediate/Build/Win64/UE4Editor/Inc/[project]" 到 includePath
Qt creator
没有尝试
- https://docs.unrealengine.com/zh-CN/Platforms/Linux/BeginnerLinuxDeveloper/SettingUpQtCreator/index.html?
- https://www.ue4community.wiki/legacy/qtcreator-in-windows-jc6qs4pv
文档
- https://docs.unrealengine.com/en-US/API/Runtime/Engine/GameFramework/AActor/index.html
- https://blog.csdn.net/yangxuan0261/article/details/52078303 TArray and TMap
- https://docs.unrealengine.com/zh-CN/Gameplay/HowTo/UsingCameras/SwitchingCameras/index.html 场景中多个摄像机的切换
- https://forums.unrealengine.com/development-discussion/c-gameplay-programming/1638743-reading-anim-curve-float-values-at-all-time
- https://docs.unrealengine.com/en-US/Engine/Rendering/Materials/HowTo/RadialMotionBlur/index.html
- https://docs.unrealengine.com/en-US/API/Runtime/Engine/Components/USceneComponent/index.html
- https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FVector/index.html
- https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FRotator/index.html
- https://docs.unrealengine.com/en-US/API/Runtime/Core/Math/FQuat/index.html
父子层级
meshComponent->SetUpAttachment(rootComponent)
将一个组件绑定在另一个组件下面
获取所有组件
TArray<UStaticMeshComponent*> comps;
GetComponents< UStaticMeshComponent>(comps); //包含根组件
debug
UE_LOG(LogTemp, Warning, TEXT("count comps: %d"), comps.Num());
UE_LOG(LogTemp, Warning, TEXT("comp: %s"), *c->GetName()); // FString
获取组件(物体)的变换
- GetActorLocation, GetComponentLocation, GetComponentTransform 返回世界坐标
- GetRelativeLocation, GetRelativeTransform 返回相对坐标
- SetRelativeLocation, SetRelativeRotation 设置相对变换
- AddActorLocalOffset, AddActorLocalRotation 增加本地空间的位移和旋转
- AddActorWorldOffset, AddActorWorldRotation 增加世界空间的位移与旋转
自定义类
- 没有任何继承的类不会出现在编辑器的内容浏览器中,虽然可以正常编译和运行,但会有一大推错误提示,也不出现书写提示
- 这种类可以修改为继承 UObject,不再使用 new xx 来创建实例,而是改用
NewObject<xx>()
来创建,不需要手动 delete - "xx.generated.h" 头文件必须是最后一个 include
添加类之后出现一堆错误
- Go to a VS solution folder. Delete following folders : ".vs", "Intermediate", "Saved"
- Delete solution (*.sln file). Keep *.uproject
- Right click on *.uproject in explorer, click "switch unreal engine versoin" and select your current engine version. Project files and solutions will get regenerated.
- Open your vs solution. Your generated files will be missing, so hit "build" button.
- Go to Tools->Options->Text editor->Advanced, set "Recreate Database" to "true" and restart visual studio
- Wait and pray for it to work (worked for me tho)
导入 fbx
blender 导出fbx时设置:Apply Scalings: All Local, Forward: X Forward, Up: Z Up 导入选项中勾选 Transform Vertex to Absolute,不要勾选:Convert Scene 可以自动调整模型单位
debug
- debug 显示找不到 ue4.exe,需要在项目管理中,在 games 项下的项目名上右击,选择 Set as startup project
物理
- AddImpulse 执行后,不会改变 GetPhysicsLinearVelocity 值。
- https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/PrimitiveComponentPhysics.cpp
- https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/PhysicsEngine/BodyInstance.cpp
- https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Source/Runtime/Engine/Private/PhysicsEngine/PhysicsInterfacePhysX.cpp
- https://github.com/NVIDIAGameWorks/PhysX/blob/4050bbfdc2699dfab7edbf0393df8ff96bbe06c5/physx/source/physxextensions/src/ExtRigidBodyExt.cpp
physX
TickGroup
- https://blog.csdn.net/qq_37712328/article/details/106674150
- Actor默认tickgroup为TG_PrePhysics,所以在tick中AddImpulse是正常的,组件的tickgroup默认未知,物理会出现抖动。
场景切换
- Open Level 节点 + Level Name
- 延时节点 Delay
- Remove from Parent 节点可以将当前 ui 移除
动画
- Play Animation 节点控制动画播放
ui
修改图片属性
- 在内容管理器中选择所有图片,右击 - Assets Actions - Bulk Edit via Property Matrix
- Compression - Compression Settings: UserInterface2D
- LevelOfDetail - Texture Group: UI
- File菜单 - Save All
添加 ui 到场景
- 打开 level blueprint
- Event Begin Play - Create Widget 选择创建好的 ui 蓝图
- 从 return value 拖出连线,选择 promote to variable,将新产生的 set 节点中的变量更名
- 从 set 节点后引出 Add to Viewport 节点添加到视图 (需要移除时使用 Remove from parent 节点)
暂停游戏
Set game paused 节点
获取玩家实例
在 ui 类或其它类中可以通过 GetPlayerPawn 节点获取玩家 pawn,再添加 CastTo<MyPawnClass>
的节点转换成自己的 pawn类
组件的变换更新
- ComponentToWorld 世界空间变换,每帧更新这个在 USceneComponent::UpdateComponentToWorldWithParent 中
- AttachChildren 子组件
- GetComponentLocation, GetComponentTransform 组件的世界变换
- bComponentToWorldUpdated
技巧
- 在 .uproject 文件上点右键,菜单中有生成 .sln 工程文件的选项
禁止启动UE4的时候启动 steamvr
修改这个文件 Program Files\Epic Games\XXXX\Engine\Plugins\Runtime\Steam\SteamVR\SteamVR.uplugin 将 "EnabledByDefault" : true, 该为 "EnabledByDefault" : false,
禁止工程中的SteamVR
菜单中 编辑->插件 找到Vertual Reality中的SteamVR,禁止它
Use Aggressive Member List for Auto... True
读取目录中所有文件
UFUNCTION(BlueprintCallable) FString ReadFile(FString filename);
FString UTextReaderComponent::ReadFile(FString filename)
{
//Read file ini [project]/Content/Data/
//you can change with other location
FString directory = FPaths::Combine(FPaths::GameContentDir(), TEXT"Data");
FString result;
IPlatformFile& file = FPlatformFileManager::Get().GetPlatformFile();
if (file.CreateDirectory(*directory)) {
FString myFile = directory + "/" + filename;
FFileHelper::LoadFileToString(result, *myFile);
}
return result;
}
{{comment.name}}{{comment.time | fDateTime}}
{{reply.name}}{{reply.time | fDateTime}}