Unreal接入指引
本文是介绍Unreal SDK的详细文档,包含了基本的接入流程,和高级的接口使用介绍。 如果想快速接入,验证平台和SDK功能,建议查看项目菜单中的“接入指南”。引导中已经按项目具体的信息(平台,引擎,国内/海外,AppID)生成了针对此项目的初始化代码,可以直接复制使用。如下图所示:

项目创建:公司外部项目支持自助创建项目,但有免费试用时长。公司内部项目,企业微信联系“CrashSight小助手”开通。
本文档适用于CrashSight SDK 4.3.x版本。4.2.x版本接入请参考旧版本Unreal SDK开发接入
1 Unreal引擎接入方案
1.1 导入 CrashSight UE Plugin
-
- 在平台成功创建项目后,在侧边栏的“接入指南”中,可以下载到与项目平台和引擎相匹配的SDK。如 下图所示:

-
- 将位于同一目录中的 Plugins 文件解压,将 Plugins 文件夹中的CrashSight目录拷贝到UE项目根目录下的Plugins目录(如果没有则创建该文件夹)。点击[文件]刷新 [Visual Studio 项目],然后在 Visual Studio 项目中则可以看到CrashSight plugin 代码以及目录结构,如图所示。

-
- 将CrashSight插件源码和项目源码一起编译,编译完成后则可以在UE编辑器中的编辑插件中看到CrashSight插件,如图所示。

1.2 将CrashSight加入依赖项
在项目主模块的Build.cs中添加:
PrivateDependencyModuleNames.AddRange(new string[] { "CrashSight" });
1.3 执行初始化
- 方法说明 选择第一个场景,或者主场景(scene), 在尽可能较早加载的脚本中调用如下代码进行初始化:
#include "CrashSightAgent.h" //请包含该头文件
using namespace GCloud::CrashSight;
#if DEBUG
CrashSightAgent::ConfigDebugMode (true);
#endif
// 设置上报域名,请根据项目发行需求进行填写。(必填)
CrashSightAgent::ConfigCrashServerUrl("UploadUrl");
// 设置上报所指向的APP ID, 并进行初始化。APP ID可以在管理端更多->产品设置->产品信息中找到。(必填)
CrashSightAgent::InitWithAppId("AppID");
- 上报域名
国内公有云:
- Android: https://android.crashsight.qq.com/pb/async
- iOS: https://ios.crashsight.qq.com/pb/sync
- Harmony: harmony.crashsight.qq.com
- Windows: pc.crashsight.qq.com
- Mac: https://mac.crashsight.qq.com/pb/sync
- PS5: https://ps5.crashsight.qq.com/pb/async
- Xbox: xbox.crashsight.qq.com
海外公有云:
- Android: https://android.crashsight.wetest.net/pb/async
- iOS: https://ios.crashsight.wetest.net/pb/sync
- Windows: pc.crashsight.wetest.net
- Mac: https://mac.crashsight.wetest.net/pb/sync
- PS5: https://console.crashsight.wetest.net/pb/async
- Xbox: xbox.crashsight.wetest.net
1.3.1 Windows配置
Windows平台还需添加崩溃捕获配置。崩溃捕获 配置有2种方案,对于可以修改引擎的项目,强烈推荐使用1.3.2.1中的方案,崩溃上报更准确。对于其他使用官方引擎版本的用户,使用1.3.2.2中的配置。
1.3.1.1 接入方案1
- 在引擎源码 \Engine\Source\Runtime\Core\Public\Windows目录下,复制入CrashSightReporter.h
- 在引擎源码 \Engine\Source\Runtime\Core\Private\Windows\WindowsPlatformCrashContext.cpp 中引入CrashSightReporter.h,在函数ReportCrash(某些宏配置下为DefaultReportCrash)函数第一行,调用FCrashSightReporter::ReportCrashToCrashSight(ExceptionInfo);
- 编译引擎
- 在初始化函数CrashSight::CrashSightAgent::InitWithAppId后调用 CrashSight::CrashSightAgent::SetVehEnable(false);
1.3.1.2 接入方案2
- 在初始化函数CrashSight::CrashSightAgent::InitWithAppId后调用 CrashSight::CrashSightAgent::SetVehEnable(true);
- 在CrashSight::CrashSightAgent::SetVehEnable(true);后调用 CrashSight::CrashSightAgent::UnrealCriticalErrorEnable(true);
1.3.2 Mac配置
在接入Mac端时,如果系统提示"CrashSight.dylib"无法打开,请执行以下命令来确保CrashSight.dylib通过MacOS的安全校验:
sudo xattr -r -d com.apple.quarantine path/to/CrashSight.dylib
1.4 Crash Reporter Client接入
Crash Reporter Client是Unreal Engine自带的崩溃上报机制,能够独立捕获并上报崩溃信息。 要通过Crash Reporter Client上报崩溃,请找到项目Config目录中的DefaultEngine.ini,在其中添加:
[CrashReportClient]
CrashReportClientVersion=1.0
DataRouterUrl="https://pc.crashsight.qq.com/csApi/ueCrc/exception/{APPID}/{VERSION}"
如果已有[CrashReportClient]块,则只需修改内容。 然后,进入项目设置->打包->高级,勾选包括崩溃报告器。 Crash Reporter Client的崩溃上报机制完全不依赖CrashSight SDK,可以单独接入,并能提供一些Unreal引擎独有的字段信息。但是需要注意的是,Crash Reporter Client仅上报崩溃,不包含错误上报等重要功能。此外,Crash Reporter Client只能设置一个DataRouterUrl,这导致CrashSight和其它崩溃上报工具不能同时使用Crash Reporter Client。
3 接口说明
全平台接口是指所有平台都通用的接口,覆盖了CrashSight的大部分基础功能,如:初始化、错误上报等。此外,每个平台可能会有一些独有的接口,会在后文单独列出。一个平台上可以使用的全部接口为:全平台接口+该平台独有的接口。
3.1 全平台接口
3.1.1 初始化
static void InitWithAppId(const char* app_id);
说明: 执行初始化工作。 在尽可能早的位置进行初始化以开启崩溃捕获和上报功能。 appid是CrashSight对项目的唯一标识,可以在产品设置->产品信息中查看。
| 参数 | 类型 | 说明 |
|---|---|---|
| app_id | const char* | 已注册项目的APP ID |
3.1.2 上报错误
static void ReportException(int type, const char* name, const char* reason, const char* stack_trace, const char* extras, bool quit, int dump_native_type = 0, bool is_async = true, const char *error_attach_path = nullptr);
说明: 主动上报错误信息。可以在捕获到错误或者需要上报的时候手动调用,支持多线程调用。 name、reason和stack_trace不能为null。
| 参数 | 类型 | 说明 |
|---|---|---|
| type | int | 异常类型, 0 ~ 3为内部保留类型传入无效, C#: 4, js: 5, lua: 6; 支持传入自定义错误类型21 ~ 30 |
| name | const char * | 异常名称 |
| reason | const char * | 异常信息 |
| stack_trace | const char * | 堆栈 |
| extras | const char * | 其他信息 |
| quit | bool | 是否退出(仅移动端有效) |
| dump_native_type | int | 0:关闭,1:调用系统接口dump(仅Android、iOS端有效),3:minidump(仅Android端有效),4:全线程堆栈(仅Android端有效) |
| is_async | bool | 是否异步(Win、Xbox有效) |
| error_attach_path | const char * | 附件的绝对路径(不支持GBK字符)(Android, iOS, Windosw) |
static void ReportExceptionW(int type, const char* name, const char* reason, const char* stack_trace, const char* extras, bool quit, int dump_native_type = 0, bool is_async = true, const wchar_t *error_attach_path);
说明: 主动上报错误信息。可以在捕获到错误或者需要上报的时候手动调用,支持多线程调用。支持带支持GBK字符的附件路径,仅Windows端有效。 name、reason和stack_trace不能为null。
| 参数 | 类型 | 说明 |
|---|---|---|
| type | int | 异常类型, C#: 4, js: 5, lua: 6 |
| name | const char * | 异常名称 |
| reason | const char * | 异常信息 |
| stack_trace | const char * | 堆栈 |
| extras | const char * | 其他信息 |
| quit | bool | 是否退出(仅移动端有效) |
| dump_native_type | int | 0:关闭,1:调用系统接口dump,3:minidump(仅移动端有效) |
| is_async | bool | 是否异步 |
| error_attach_path | const wchar_t * | 附件的绝对路径 (Win, Xbox) |
注:dump_native_type关闭(0)时错误异步上报,开启时为同步上报。推荐仅在卡死或严重错误时使用该功能获取额外信息。
页面查看:
extras:崩溃详情页->附件下载->extraMessage.txt
dump:崩溃详情页->附件下载->trace.zip
其它:上报错误耗时
| Android | iOS | |||
|---|---|---|---|---|
| 附件大小 | dump堆栈 | 不dump堆栈 | dump堆栈 | 不dump堆栈 |
| 100K | [0.498881]s | [0.003127]s | [0.117762]s | [0.001172]s |
| 10K | [0.464859]s | [0.000730]s | [0.115362]s | [0.000445]s |
| 1K | [0.477934]s | [0.000189]s | [0.117078]s | [0.000293]s |
static void ReportExceptionJson(int type, const char* exception_name, const char* exception_msg, const char* exception_stack, const char* params_json, int dump_native_type = 0, const char* errorAttachmentPath = "");
说明: 主动上报错误信息,其它信息必须为Json字符串,可以指定上传附件。
| 参数 | 类型 | 说明 |
|---|---|---|
| type | int | 异常类型, C#: 4, js: 5, lua: 6 |
| exception_name | const char * | 异常名称 |
| exception_msg | const char * | 异常信息 |
| exception_stack | const char * | 堆栈 |
| params_json | const char * | 其他信息, map编码的Json字符串 |
| dump_native_type | int | 0:关闭,1:调用系统接口dump,3:minidump |
| errorAttachmentPath | const char * | 附件的绝对路径 |
页面查看:
paramsJson:崩溃详情页->附件下载->extraMessage.txt
Native堆栈:崩溃详情页->附件下载->trace.zip
3.1.3 设置用户ID
static void SetUserId(const char* user_id);
说明: 设置用户ID。用户id默认为unknown。
| 参数 | 类型 | 说明 |
|---|---|---|
| user_id | const char * | 用户ID |
3.1.4 添加自定义数据
static void AddSceneData(const char* key, const char* value);
说明:设置用户自定义的 Key-Value 数据,将在发送 Crash 时随异常信息一起上报,单个key长度限制100字符,单个value限制1000字符,总长度(所有key+value)限制(Android 64KB,iOS 128KB)
页面查看:崩溃详情页->附件下载->valueMapOthers.txt
| 参数 | 类型 | 说明 |
|---|---|---|
| key | const char * | 键 |
| value | const char * | 值 |
3.1.5 设置应用版本
static void SetAppVersion(const char* app_version);
说明:设置应用版本号
Android 默认使用AndroidManifest.xml文件的versionName属性
iOS 配置Info.plist, {CFBundleShortVersionString}.{CFBundleVersion} 组合成app版本号
备注:需要在InitWithAppId接口之前调用。
| 参数 | 类型 | 说明 |
|---|---|---|
| app_version | const char * | 版本号 |
3.1.6 上报域名设置
static void ConfigCrashServerUrl(const char* crash_server_url);
说明:设置上报域名。
备注:需要在InitWithAppId接口之前调用。
国内公有环境域名如下:
直接接入CrashSight域名与MSDK转接不同,请务必重新依照上述域名配置。其他环境域名请咨询接入接口人。
| 参数 | 类型 | 说明 |
|---|---|---|
| crash_server_url | const char * | 要上报的域名 |
3.1.7 设置上传日志路径
static void SetLogPath(const char* log_path);
说明:设置崩溃后上传的日志路径,需要可读权限。在Android和iOS端上,该接口的优先级低于日志路径回调。Windows端上不支持带GBK字符的附件路径。 PS4、PS5、Switch不可用,鸿蒙暂不可用
| 参数 | 类型 | 说明 |
|---|---|---|
| log_path | const char * | 日志绝对路径 |
static void SetLogPathW(const wchar_t* log_path);
说明:设置崩溃后上传的日志路径,需要可读权限。仅Windows端可用,支持带GBK字符的附件路径。
| 参数 | 类型 | 说明 |
|---|---|---|
| log_path | const wchar_t * | 日志绝对路径 |
3.1.8 debug使能开关
static void ConfigDebugMode(bool enable);
说明:是否开启debug模式,默认为关。开启后会打印一定量的日志,但是可以方便测试期间的问题定位。
备注:需要在InitWithAppId接口之前调用。
| 参数 | 类型 | 说明 |
|---|---|---|
| enable | bool | debug使能开关 |
3.1.9 设置设备ID
static void SetDeviceId(const char* device_id);
说明:设置设备ID,默认采用uuid作为设备ID Win、Xbox、PS4、PS5、Switch、鸿蒙暂不可用
备注:需要在InitWithAppId接口之前调用。
| 参数 | 类型 | 说明 |
|---|---|---|
| device_id | const char * | 设备ID |
3.1.10 设置自定义日志上报级别
static void ConfigCrashReporter(int log_level);
说明:设置自定义日志上报级别 Off=0,Error=1,Warn=2,Info=3,Debug=4 , 默认Info。
备注:需要在InitWithAppId接口之前调用。
| 参数 | 类型 | 说明 |
|---|---|---|
| log_level | int | 日志级别 |
3.1.11 自定义日志
static void PrintLog(LogSeverity level, const char* format, ...);
说明:自定义日志,限制30KB
| 参数 | 类型 | 说明 |
|---|---|---|
| level | LogSeverity | 日志级别 |
| format | const char * | 日志格式 |
| args | params object[] | 可变参数 |
static void PrintLog(LogSeverity level, const char* tag, const char* format, ...);
说明:自定义日志,限制30KB Android、iOS、Linux暂不可用
| 参数 | 类型 | 说明 |
|---|---|---|
| level | CSLogSeverity | 日志级别 |
| tag | const char * | 日志标签 |
| format | const char * | 日志格式 |
| args | params object[] | 可变参数 |
自定义日志查看: Android、iOS、PS4、PS5、Switch:问题详情->跟踪日志->custom log Windows、Xbox、Linux:问题详情->自定义日志(来自接口)
3.1.12 上报轻量级日志
static void ReportLogInfo(const char* msg_type, const char* msg);
说明:上报轻量级日志
| 参数 | 类型 | 说明 |
|---|---|---|
| msg_type | const char * | 日志类型 |
| msg | const char * | 日志内容 |
3.1.13 标记场景
static void SetScene(int scene_id);
说明: 设置场景ID,每一个联网或者上报都可以携带该字段,实现针对不同的子场景计算崩溃率等数据。
| 参数 | 类型 | 说明 |
|---|---|---|
| scene_id | int | 场景ID |
3.1.14 设置发行渠道
static void SetEnvironmentName(const char *serverEnv);
说明: 设置发行渠道,每一个联网或者上报都可以携带该字段,可实现针对不同的发行渠道统计数据。
| 参数 | 类型 | 说明 |
|---|---|---|
| serverEnv | const char * | 发行渠道名称 |
3.2 Android、iOS、Mac端接口
3.2.1 回调开关
static void ConfigCallbackType(int32_t callback_type);
说明:各类上报的回调开关,目前是5种类型,用5位表示。第一位表示crash,第二位表示anr,第三位表示u3d c# error,第四位表示js,第五位表示lua,默认全开。
| 参数 | 类型 | 说明 |
|---|---|---|
| callback_type | int32_t | 回调开关 |
3.2.2 设置Android手机型号
static void SetDeviceModel(const char* device_model);
说明:设置手机型号
备注:需要在InitWithAppId接口之前调用。
| 参数 | 类型 | 说明 |
|---|---|---|
| device_model | const char * | 手机型号 |
3.2.3 开启多信号捕获
static void SetCatchMultiSignal(bool enable);
说明: 捕捉来自不同线程的多个信号,并上传第一个信号的信息,默认关闭。
| 参数 | 类型 | 说明 |
|---|---|---|
| enable | bool | 多信号捕获开关 |
3.2.4 启用上报最后一帧
static void SetUnwindExtraStack(bool enable);
说明: 最多回溯256帧,即使栈字符串已满,也会上报最后一帧,默认关闭。
| 参数 | 类型 | 说明 |
|---|---|---|
| enable | bool | 上报最后一帧开关 |
3.2.5 获取崩溃线程ID
static long GetCrashThreadId();
说明: 当崩溃发生时,获取崩溃线程ID,失败时返回-1,可在回调中调用
3.2.6 设置自定义device ID
static void SetCustomizedDeviceID(const char* device_id);
说明: 设置自定义device ID
| 参数 | 类型 | 说明 |
|---|---|---|
| device_id | const char* | 自定义device ID |
3.2.7 获取SDK生成的device ID
static void GetSDKDefinedDeviceID(void* data, int len);
说明: 获取SDK生成的device ID
| 参数 | 类型 | 说明 |
|---|---|---|
| data | void* | 指向用于存放device ID的内存 |
| len | int | data的长度 |
3.2.8 设置自定义match ID
static void SetCustomizedMatchID(const char* match_id);
说明: 设置自定义match ID,match id可用于在“高级搜索”中查找崩溃和错误
| 参数 | 类型 | 说明 |
|---|---|---|
| match_id | const char* | match ID |
3.2.9 获取SDK生成的session ID
static void GetSDKSessionID(void* data, int len);
说明: 获取SDK生成的session ID,session ID用于唯一标记一次启动,一般用于在回调中确定是否为同一次启动。
| 参数 | 类型 | 说明 |
|---|---|---|
| data | void* | 指向用于存放session ID的内存 |
| len | int | data的长度 |