Unity,在开启了[BurstCompile]
之后,编辑器可以正常运行,但在真机上会闪退,日志显示:
Unable to find internal function Unity.Burst.LowLevel.BurstCompilerServices::GetOrCreateSharedMemory
这是因为开启了打包选项中,剥离代码的高级水平,如下图
事实上,在官方文档中就指出,High Stripping Level
需要使用link.xml
来定制,代码具体的剥离规则。
When you select the High Managed Stripping Level, UnityLinker removes
as much unreachable code as possible and produces smaller builds than
Medium stripping level. High stripping level prioritizes size
reduction over usability; you might need add link.xml files, Preserve
attributes, or even rewrite problematic sections of code.
link.xml
由我们自己创建,放在任意资源目下即可,为了防止Burst
被剔除,我们加入下面这句:
<linker>
<assembly fullname="Unity.Burst" preserve="all"/>
</linker>
然后,问题就解决了,其它类似问题,都可以通过定制link.xml
来解决,具体参看:官方文档中。