Unity 控制台消息和日志文件可以包含详细的堆栈跟踪信息。控制台还会链接到生成该消息的代码行。这在您想要识别导致日志条目出现的那一行、方法或函数调用序列时非常有用。
提示:检查代码的另一种方法是将调试器附加到编辑器或构建的播放器。
Unity 可以为托管和非托管代码提供堆栈跟踪信息
托管代码:在 Unity 中运行的托管 DLL 或 C# 脚本一段代码,允许您创建自己的组件、触发游戏事件、随时间推移修改组件属性并以任何您喜欢的方式响应用户输入。 更多信息
参见 术语表。这些可以是随 Unity 一起提供的脚本、您编写的自定义脚本、包含在 Asset Store一个不断增长的免费和商业资产库,由 Unity 和社区成员创建。提供各种各样的资产,从纹理、模型和动画到整个项目示例、教程和编辑器扩展。 更多信息
参见 术语表 中的 插件在 Unity 之外创建的一组代码,在 Unity 中创建功能。在 Unity 中可以使用两种类型的插件:托管插件(使用 Visual Studio 等工具创建的托管 .NET 程序集)和原生插件(特定于平台的原生代码库)。 更多信息
参见 术语表 的第三方脚本,或在引擎中运行的任何其他 C# 脚本。
非托管代码:原生 Unity 引擎代码,或来自直接在您的计算机或目标构建平台上运行的原生插件的代码。非托管代码通常是从 C 或 C++ 代码编译而来。只有在您拥有原生二进制文件的原始源代码时才能访问它。通常,只有在您需要确定错误是由您的代码还是引擎代码导致的,以及引擎代码的哪一部分时,才会使用非托管代码的堆栈跟踪。
Unity 提供三种堆栈跟踪选项
解析堆栈跟踪,尤其是完整堆栈跟踪,是一个资源密集型操作。堆栈跟踪的一些最佳实践包括
注意:堆栈跟踪选项是一个构建设置,会影响构建的播放器。它不是编辑器中的视图首选项。
要指定在堆栈跟踪中包含多少详细信息,可以使用脚本 API 或编辑器
要通过脚本 API 控制堆栈跟踪日志记录,请使用 Application.SetStackTraceLogType。您可以使用 API 在播放器构建之前或运行时更改堆栈跟踪设置。
要使用播放器设置窗口,请选择编辑 > 项目设置 > 播放器 > 其他设置。使用新设置重新构建您的播放器。
消息的完整文本包括对代码文件中特定行的引用以及链接。单击任何链接以在您的 IDE 中打开引用的代码行所在的文件。
构建的应用程序不会输出到控制台。要查看堆栈跟踪,使用应用程序的日志文件。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.