UE5.5 在 Windows 中构建 CARLA-0.10.0
1. 确保以下软件已正确安装:
Windows 11
Visual Studio 2022(带 C++ 组件)
Python 3.9(推荐,不要使用 3.10 或 3.12)
Unreal Engine 5.5 [5.3或者5.4 会因为VS2022的底层类名问题出错]
Git
CMake 3.22+
Ninja
Windows 11 SDK
2. 下载资源
从https://github.com/carla-simulator/carla/releases 下载Asset 源码(直接下载是预编译版本 无法使用UE editor)
在系统中设置环境变量:CARLA_UNREAL_ENGINE_PATH “F:\EPIC\UE_5.5”
CarlaSetup.bat 双击就行 会下载一些content资源和需要的包 如果你电脑是比较干净的,那更好了,这个bat自动把UE5.5包括其他的东西给你下载完。
3. 进入 CARLA 目录
创建 Python 3.9 虚拟环境 python -m venv venv39
激活 venv39\Scripts\activate.bat
检查 python --version
安装依赖 pip install --upgrade pip setuptools wheel build 或者 requirement.txt
【没有pip的话 执行python -m ensurepip --default-pip;pip install setuptools wheel build numpy 】
ps:删除之前的build目录 rmdir /S /Q Build【如果遇到失败】
4. 运行 CMake 配置
在下载的Carla0.10.0中打开 VS 2022 的 x64 Native Tools 命令提示符输入
cmake -G Ninja -S . -B Build ^
-DCMAKE_BUILD_TYPE=Release ^
-DBUILD_CARLA_UNREAL=ON ^
-DCARLA_UNREAL_ENGINE_PATH=%CARLA_UNREAL_ENGINE_PATH% ^
-DCMAKE_Fortran_COMPILER= ^
-DPython3_EXECUTABLE="F:/Carla/carla-0.10.0/venv39/Scripts/python.exe" ^
-DCMAKE_C_FLAGS="/utf-8" ^
-DCMAKE_CXX_FLAGS="/utf-8"
^
-DCMAKE_C_COMPILER="D:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\cl.exe" ^
-DCMAKE_CXX_COMPILER="D:\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64\cl.exe"
运行编译
cmake --build Build
这里还是可能遇到问题,尽量把所有进程都关闭 留给Cmake
编译 Python API
cmake --build Build --target carla-python-api-install
python -c "import carla; print('CARLA version:', carla.__version__)"
启动 Unreal Editor
cmake --build Build --target launch
这里遇到问题, Visual Studio 2022 版本过低, 通过Visual Studio Installer 更新 Visual Studio 2022,然后检查 & 安装 MSVC 14.34+【点击 “修改”(Modify),进入 “单个组件” 选项卡,在 “编译工具”(Compilers, build tools)里,找到MSVC v143 - VS 2022 C++ x64/x86 build tools 】 卸载MSVC 2019 和 2017 解决
新问题,启动 Unreal Editor这一步检测到:
std::atomic_store_expression
std::atomic_store_explicit 和 std::atomic_load_explicit 已被 C++20 废弃
所以如果我想修复错误,就需要在AtomicSharedPtr.h中修改为store 和 load,但在更改了上一步后,cmake --build Build 又给我带来了问题,因为它使用的是旧版本的 store 和 load。
解决问题,不能去修改AtomicSharedPtr.h,会产生各种奇葩错误。最后研究Log.txt发现是UE5.5 移除了 ParallelLineTraceSingleByChannel()
,改用 LineTraceSingleByChannel()
所以我需要修改
…\carla-0.10.0\Unreal\CarlaUnreal\Plugins\Carla\Source\Carla\Sensor 中的Radar.cpp和RayCastSemanticLidar.cpp,具体:
修改 Radar.cpp
找到 Radar.cpp
的 SendLineTraces()
函数:
const bool Hitted = GetWorld()->ParallelLineTraceSingleByChannel(
OutHit,
RadarLocation,
EndLocation,
ECC_GameTraceChannel2,
TraceParams,
FCollisionResponseParams::DefaultResponseParam
);
// 修改为
const bool Hitted = GetWorld()->LineTraceSingleByChannel(
OutHit,
RadarLocation,
EndLocation,
ECC_GameTraceChannel2,
TraceParams,
FCollisionResponseParams::DefaultResponseParam
);
找到 RayCastSemanticLidar.cpp
的 ShootLaser()
函数:
GetWorld()->ParallelLineTraceSingleByChannel(
HitInfo,
LidarBodyLoc,
EndTrace,
ECC_GameTraceChannel2,
TraceParams,
FCollisionResponseParams::DefaultResponseParam
);
// 修改为
GetWorld()->LineTraceSingleByChannel(
HitInfo,
LidarBodyLoc,
EndTrace,
ECC_GameTraceChannel2,
TraceParams,
FCollisionResponseParams::DefaultResponseParam
);
终于成功了,都是泪,官方文档坑太多了…