UE遇到的各种问题

使用最新版本vs2022时,UE5.4无法创建成功UEC++项目

Running E:/Epic/UE_5.4/Engine/Build/BatchFiles/Build.bat Development Win64 -Project=”E:/UE/UE5/FirDemo/FirDemo.uproject” -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE Using bundled DotNet SDK version: 6.0.302 Running UnrealBuildTool: dotnet “....\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll” Development Win64 -Project=”E:/UE/UE5/FirDemo/FirDemo.uproject” -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE Log file: C:\Users\liks\AppData\Local\UnrealBuildTool\Log.txt Available x64 toolchains (1): * D:\env\vs2022\VC\Tools\MSVC\14.44.35207 (Family=14.44.35207, FamilyRank=5, Version=14.44.35208, Is64Bit=True, ReleaseChannel=Latest, Architecture=x64) Visual Studio 2022 compiler version 14.44.35208 is not a preferred version. Please use the latest preferred version 14.38.33130 Available x64 toolchains (1): * D:\env\vs2022\VC\Tools\MSVC\14.44.35207 (Family=14.44.35207, FamilyRank=5, Version=14.44.35208, Is64Bit=True, ReleaseChannel=Latest, Architecture=x64) Visual Studio 2022 compiler version 14.44.35208 is not a preferred version. Please use the latest preferred version 14.38.33130 Creating makefile for FirDemoEditor (no existing makefile) Available x64 toolchains (1): * D:\env\vs2022\VC\Tools\MSVC\14.44.35207 (Family=14.44.35207, FamilyRank=5, Version=14.44.35208, Is64Bit=True, ReleaseChannel=Latest, Architecture=x64) Visual Studio 2022 compiler version 14.44.35208 is not a preferred version. Please use the latest preferred version 14.38.33130 Available x64 toolchains (1): * D:\env\vs2022\VC\Tools\MSVC\14.44.35207 (Family=14.44.35207, FamilyRank=5, Version=14.44.35208, Is64Bit=True, ReleaseChannel=Latest, Architecture=x64) Visual Studio 2022 compiler version 14.44.35208 is not a preferred version. Please use the latest preferred version 14.38.33130 @progress push 5% Parsing headers for FirDemoEditor Running Internal UnrealHeaderTool E:\UE\UE5\FirDemo\FirDemo.uproject E:\UE\UE5\FirDemo\Intermediate\Build\Win64\FirDemoEditor\Development\FirDemoEditor.uhtmanifest -WarningsAsErrors -installed Total of 14 written Reflection code generated for FirDemoEditor in 0.8866635 seconds @progress pop Building FirDemoEditor… Using Visual Studio 2022 14.44.35208 toolchain (D:\env\vs2022\VC\Tools\MSVC\14.44.35207) and Windows 10.0.26100.0 SDK (C:\Program Files (x86)\Windows Kits\10). Warning: Visual Studio 2022 compiler is not a preferred version Determining max actions to execute in parallel (14 physical cores, 20 logical cores) Executing up to 14 processes, one per physical core Requested 1.5 GB memory per action, 5.85 GB available: limiting max parallel actions to 3 Using Parallel executor to run 19 action(s) —— Building 19 action(s) started —— [1/19] Resource Default.rc2 [2/19] Compile [x64] SharedPCH.UnrealEd.Project.ValApi.Cpp20.cpp E:\Epic\UE_5.4\Engine\Source\Runtime\Core\Public\Experimental\ConcurrentLinearAllocator.h(31): error C4668: û?????__has_feature?????ΪԤ?????꣬???0???????#if/#elif?? E:\Epic\UE_5.4\Engine\Source\Runtime\Core\Public\Experimental\ConcurrentLinearAllocator.h(31): error C4067: Ԥ????ָ????????- Ӧ??????? E:\Epic\UE_5.4\Engine\Source\Runtime\Engine\Classes\Engine\SkeletalMesh.h(930): warning C4996: ‘FBoneMirrorInfo’: FBoneMirrorInfo is deprecated. Please use UMirrorDataTable for mirroring support. Please update your code to the new API before upgrading to the next release, otherwise your project will no longer compile. Total time in Parallel executor: 20.44 seconds Total execution time: 24.20 seconds

错误代码如上所示

原因:按照UE官方给的版本推荐是vs2022 17.4或者更高版本,但是在VS 2022 17.13.5之后的版本中,14.38.33130版本的MSVC会被删除,替换成14.43.34808版本,而UE 5.4并不支持这个版本,所以UE 5.4建议使用VS 2022 17.4-17.8版本

VS 2022 17.8.3版本下载

下面给出VS 2022 17.8.3版本的下载地址:https://download.visualstudio.microsoft.com/download/pr/63b5064f-af60-4cbe-96cd-a9dd9d41ee3d/77d65fe2bfc509ca5cd190cec9e48b62c98195d6fc5297113c91819776abb047/vs_Community.exe

另外附上另一种下载VS 2022前置版本的方法,不过这种方法无法改变 VS的下载位置,只能下载在C盘上

另一种方法

按下 Win+R,输入 cmd,然后按下回车,打开命令提示符。输入:

1
winget show --versions "Microsoft.VisualStudio.2022.Community"

按下回车运行。

系统输出一列 17.x.x 格式的版本号,从中找到你需要安装的版本。

此处以 17.9.1 版本为例,输入(注意把里面的 17.9.1 替换成您实际需要安装的版本):

1
winget install -v 17.9.1 "Microsoft.VisualStudio.2022.Community"

按下回车运行,就会开始安装对应版本的 Visual Studio。

(安装过程中,可能会弹出提示 Do you agree to all the source agreement terms? [Y] Yes [N] No:

如果弹出了以上提示,输入 y,按下回车运行。)

如何将UE5的蓝图节点从英文改为中文

image-20250602102434694

打上勾即可

导入FBX模型不是一个整体

[!warning]

把“合并网格体”打勾,同时取消 骨架网格体 的勾选

image-20250618111001170

如何使用UEC++实现UE蓝图中的方法

说在前面:UE蓝图推荐使用英文版本,这样才能更好找到对应的库在哪里,以及库中的函数名称

方法1:使用UE蓝图给的蓝图方法解释,然后自己去库里寻找对应的函数

方法2:使用AI直接截图蓝图中的方法去搜索对应的C++函数

本文这里只介绍方法1

例子1

image-20250628170938572

[!Warning]

在UEC++中的代码就在KismetSystemLibrary.h中,我们在UEC++中搜索KismetSystemLibrary库,即可得到对应的函数

注:找到对应方法后,我们还需要判断参数是否准确

image-20250628171159895

例子2

image-20250628171953536

[!Warning]

根据图中我们可以知道该方法是在GameplayStatics.h中,故我们去这个GameplayStatics库里面寻找对应的结果。如下图,第一次我们发现没有找到;这时候只需要把中间的空格去掉即可

注:找到对应方法后,我们还需要判断参数是否准确

image-20250628172155701

image-20250628172242386

世界中存在一个不是自己放置的类

自己在世界中只放入了一个Spine类的蓝图BP_Spine,为什么UGameplayStatics::GetAllActorsOfClass(World, ASpine::StaticClass(), FoundActors);获取到的ASpine类型有两个:一个Spine0,一个自己放置的BP_Spine

原因:在另一个C++类中调用ASpine类中函数的时候,使用GetWorld()->SpawnActor<ASpine>(...)函数,此函数作用是创建一个动态对象,确保对象存在于世界中,灵活控制生成条件

image-20250629133056598

于是,使用GetAllActorsOfClass获取到的结果有两个,一个为动态对象,一个是自己放置在世界中的蓝图类。

在一个C++类中调用另一个C++类中的变量或者函数

假设在A类中调用B类的变量C和函数D

  1. 在A类中找到B类的Actor,并创建引用G
  2. 直接使用G来获取变量C和执行函数D

Get All Actors of Class的替代

GetAllActorsOfClass 是 Unreal Engine 中用于获取场景中所有属于特定类的活动 Actor 的函数。虽然它功能强大,但也有其局限性和潜在的性能问题,特别是当场景中有大量 Actor 时。它的主要缺点包括:

  1. 性能开销GetAllActorsOfClass 需要遍历整个场景中的所有 Actor 来查找符合指定类的对象,这在 Actor 数量较多的情况下可能会导致显著的性能下降。
  2. 频繁调用的影响:如果在每一帧或非常频繁地调用 GetAllActorsOfClass,会对游戏性能产生负面影响,因为它每次都被强制执行一次完整的搜索过程。

替换方案

C++中

  1. **使用TActorIterator**:对于只需要一次性查找的情况,可以使用 TActorIterator(C++)或蓝图中的相应节点。相比 GetAllActorsOfClass,这种方式提供了更细粒度的控制,允许你边迭代边处理Actor,而不需要首先将它们全部收集到一个数组中。
  2. **利用GameModeGameStatePlayerController**:如果你需要查询的是特定类型的对象(如玩家角色),可以通过 UGameplayStatics::GetPlayerCharacter 或访问 AGameModeBase/AGameStateBase 来直接获取,而不是遍历所有Actor。

蓝图中

自定义的C++函数,该函数内部使用 TActorIterator 来收集所需Actor的信息,然后通过标记为 BlueprintCallable 的方式暴露给蓝图,使得可以在蓝图中调用此功能。

TActorIterator的使用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ASpine* SpineActor = nullptr;
for (TActorIterator<ASpine> It(GetWorld()); It; ++It)
{
SpineActor = *It;
// 返回false,详情见下一个问题
if (SpineActor->GetName() == "BP_Spine") UE_LOG(LogTemp, Warning, TEXT("找到了BP_Spine"));
// 返回true,是同一个类型
if (SpineActor->IsA(ASpine::StaticClass())) UE_LOG(LogTemp, Warning, TEXT("是同一个类型"));

if (SpineActor && SpineActor->GetName().Contains("BP_Spine"))
{
UE_LOG(LogTemp, Warning, TEXT("Found BP_Spine: %s"), *SpineActor->GetName());
// 处理找到的 SpineActor
}
}
if (!SpineActor)
{
UE_LOG(LogTemp, Warning, TEXT("未找到名为 BP_Spine 的 Actor"));
return EBTNodeResult::Failed;
}

蓝图Actor的名字和在世界中获取到的Actor中的名字不相同

在 Unreal Engine 中,看到的对象名称是 BP_Spine_C_UAID_9C2DCD7A0EEE7A7502_2058130519 ,而在编辑器中创建的蓝图资产名称是 BP_Spine

出现原因

  1. 在 UE 中,每个被加载进关卡的 Actor 实例都会有一个唯一的名称,即使它们来自同一个蓝图类。引擎会自动在类名后加上 _C(表示 Class)以及一串唯一标识符(UAID),例如:

    1
    BP_Spine_C_UAID_9C2DCD7A0EEE7A7502_2058130519
  2. 蓝图资产名 vs 实例名

    • 蓝图资产名(Blueprint Name):BP_Spine 这是你在内容浏览器中看到的蓝图资源名称,是一个“模板”或“类型”。
    • 实例名(Instance Name):BP_Spine_C_UAID_9C2DCD7A0EEE7A7502_2058130519 这是该蓝图在世界中具体生成的一个实例对象的名称。