Unity的一些问答
开发中遇到了很多比较奇怪和难解决的问题,这里进行了一些记录,很多问题得到Unity官方技术支持同学的大力帮助,非常感谢!Unity5.5.1p2版本,IL2CPP切到后台可能会报错:
EGL
Unable to acquire context EGL_BAD_NATIVE_WINDOW a nativewindowtype argument
does not refer to a valid native window.
解决方案:
官方建议只要没有Crash可以忽略。
The
error message "Unable to acquire context - EGL_BAD_NATIVE_WINDOW: A
NativeWindowType argument does not refer to a valid native window" occurs
occasionally on some Android devices when restoring the app from a minimised
state.
This
issue has been reported as a bug and we are currently working on a fix.
Other
than creating noise in logs and crash dumps the the error causes no problems so
you are safe to ignore it.
第一次安装完apk包之后,在刚进游戏启动瞬间游戏切到后台必定会闪退。Unity会弹框提示:Error
Failed to extract resources needed by il2cpp。
解决方案:
官方反馈在5.6版本得到修复。因为升级版本风险太高,这个bug影响较小,继续尝试其他解决方案。
Having
looked through the forum post you mentioned. As-well as the bug reports
mentioned in there and searching for other reports:
It
looks like these particular reports, were possibly fixed in 5.6 via other fixes
and changes. But we have no local report that we have been able to reliably
find a concrete fix or evidence of a fix with.
The
error message is flagged when the file system fails to copy files needed.
Can
you check if the devices being affected have this problem have little disk
space free?
Have
you been able to test the issue in 5.6 and see if the problem persists?
Unity是否有获得设备唯一ID的功能?新版IOS唯一ID的接口SystemInfo.deviceUniqueIdentifier可能重复。
解决方案:
没有直接的api。官方建议如下
https://forum.unity3d.com/threads/ios-advertising-identifier-rejection-faq.226187/
升级UNITY5.5.1P2版本之后MAC机上报错:
Extension
was not registered, that means it relies on default UnityExtensions settings,
please register extension and apply necessary settings for it in the callback.
解决方案:
官方建议如下。
The error is caused by importers
which have a zero length asset path name. This happens when you have a Unity
version installed with an addon, it's calling for an asset's physical location,
and if you save the project and open with a Unity version without the addon it
will return an empty string since the physical location of this asset doesn't
exist. So the fix in 5.6 Unity will skip initialization for these plugins. If
you later add the addon, upon project opening it will return a valid path and
settings for it will be initialized.
This issue is not supposed to
affect your project or the editor.
In order to get rid off this
error just try to reimport all assets, it should solve the issue.
升级Unity之后IOS出包时报错。Showing
Recent Issues ld:
'/Users/hanyufei/.jenkins/workspace/MGameIOSMacPro/mgame/Program/trunk/Client/0.0.17.0/Libraries/Plugins/iOS/libulua.a(array.o)'
does not contain bitcode. You must rebuild it with bitcode enabled (Xcode
setting ENABLE_BITCODE), obtain an updated library from the vendor, or
disable bitcode for this target. for architecture armv7
解决方案:
使用的Lua库不支持BitCode。一种是升级Lua库支持BitCode,一种是关闭BitCode功能,但是会增大包体。这个bug出现在升级Unity5.5之后,主要是Unity5.3.1p1开始,bitcode是默认打开的。
升级Unity5.5之后出包报错:
2017-02-14
12:09:10.329 xcodebuild PluginLoading: Required plug-in
compatibility UUID E0A62D1F-3C18-4D74-BFE5-A4167D643966 for plug-in at path
'~/Library/Application
Support/Developer/Shared/Xcode/Plug-ins/Unity4XC.xcplugin' not present in
DVTPlugInCompatibilityUUIDs
===
BUILD TARGET Unity-iPhone OF PROJECT Unity-iPhone WITH THE DEFAULT
CONFIGURATION (Release) ===
Check
dependencies
Signing
for "Unity-iPhone" requires a development team. Select a development
team in the project editor.
Code
signing is required for product type 'Application' in SDK 'iOS 10.2'
解决方案:
因为升级之后多了AutoSign选项并默认开启导致证书和签名设置不正确导致。
Animator性能的问题:
为每个角色制作一个Animator
controller同为所有角色制作一个Animator controller并采用Animator controller
override去填充每个角色动画这两种方式的问题:
1-相同状态机结构下,两者之间在内存占用上,哪一种会更多?
2-相同状态机结构下,哪一种占用cpu会更多?
3-部分角色用不到全部的动作,如果不指定这些动作,是否会在内存占用以及cpu占用上更省?
4-一个角色一个独立animator
controller与一个角色独立animator controller并且使用Animator controller
override去替换自身动作在效率上有没有损害
5-能否比较详细的描述下Animator
controller,Animator controller override的工作原理以及内存占用,cpu占用方面的详细情况
解决方案:
官方反馈如下。
第一和第二个问题:内存方面,使用Animator
override
controller会更加节省内存,开发效率上也会更高,cpu占用差异两者基本可以忽略。动画的瓶颈大多都在计算骨骼和skin上。如果使用blend
tree的话会有动画融合的消耗。特别的,使用一个大型、复杂的状态机(animator controller)需要注意其初始化开销。
第三个问题:
是的,理论上越精简的controller是会占用更少的资源的。不过因为不同角色使用相同的animator
controller并不会增大内存,角色只是引用了controller,而如果新建一个精简的controller则会有额外的内存消耗。所以是否新建controller需要斟酌一下。
第四个问题:
对于不同的角色使用animator
controller,我们建议的最佳实践是:尽可能简化animator controller的内部逻辑,可以适当把不同逻辑放在多个animator
controller中,再使用Animator controller override去动态替换animation
clip;而不要使用一个大型的、复杂的、全能的、包含所有逻辑的animator controller。
第五个问题:
简单来说,Animator
controller是一个动画状态树。而blend tree则类似于ue和cryEngine的blend space。Animator
controller如果使用blend tree的话,则内存占用会多一些。
Animator
override controller可以简单理解为一个实例化的animator controller,所以在内存占用上会小于它所引用的animator
controller。
PS:最后发现使用Animator性能开销还是比较高,并且把Animator下面的树删光开销也没有明显下降。最终还是把很多简单的动作改为了Animation。
我们不但使用了Bugly来收集错误和crash,还使用了Unity官方的GAMEPERFORMANCE,但是升级5.5之后虽然不用集成插件了,但是也不能自定义版本号和玩家ID了,这样就不能进行一些过滤甚至开发过程中编辑器出现的临时error也会上报,很是不方便。
解决方案:
升级之后确实没有了,只能当作一个feature反馈,希望能早日开发。
魅蓝3S会无限旋转。
解决方案:
确认是陀螺仪的问题导致,Unity开启陀螺仪在魅蓝3S上就会无限旋转,其他游戏有会有这个问题。可以在这个设备上关闭陀螺仪。
游戏开始时切出去,登陆画面会变窄
解决方案:
确认是开始时切出去会连续切换两次分辨率。修改相关代码加判断防止切换两次。
Unity物理相关的崩溃:
1#00 pc cbea16b0 <unknown>
2#01 pc 006a1920 libunity.so CastFilter::preFilter(physx::PxFilterData
const&, physx::PxShape const*, physx::PxRigidActor const*,
physx::PxFlags<physx::PxHitFlag::Enum, unsigned short>&)
3#02 pc 00f32090 libunity.so
MultiQueryCallback<physx::PxOverlapHit>::invoke(float&,
physx::Sq::PrunerPayload const*, unsigned int)
4#03 pc 01053f90 libunity.so BucketPrunerOverlapTraversal<OBBAABBTest_SIMD,
false>::operator()(physx::Sq::BucketPrunerCore const&, OBBAABBTest_SIMD
const&, physx::Sq::PrunerCallback&, physx::PxBounds3 const&)
(.part.26)
5#04 pc 010594c0 libunity.so
physx::Sq::BucketPrunerCore::overlap(physx::Sq::ShapeData const&,
physx::Sq::PrunerCallback&) const
6#05 pc 0104ce88 libunity.so physx::Sq::AABBPruner::overlap(physx::Sq::ShapeData
const&, physx::Sq::PrunerCallback&) const
7#06 pc 00f3383c libunity.so bool
physx::NpSceneQueries::multiQuery<physx::PxOverlapHit>(physx::MultiQueryInput
const&, physx::PxHitCallback<physx::PxOverlapHit>&,
physx::PxFlags<physx::PxHitFlag::Enum, unsigned short>, physx::PxQueryCache
const*, physx::PxQueryFilterData const&, physx::PxQueryFilterCallback*,
physx::BatchQueryFilterData*) const
解决方案:
升级Unity的物理引擎之后解决,应该是Physx的bug。
使用il2cpp的包比mono的大12M。
解决方案:
因为会额外生成一些代码所以il2cpp会比mono大,官方提供一些缩小包体的建议
http://docs.unity3d.com/Manual/ReducingFilesize.html
http://docs.unity3d.com/Manual/iphone-playerSizeOptimization.html
http://forum.unity3d.com/threads/il2cpp-build-size-improvements.322079/
ANDROID的包在固定设备上,华为荣耀3X上启动黑屏闪退。
解决方案:
只有这台设备会出现,存在兼容性问题。测试编译使用IL2CPP并且不开启Development开关不会闪退,使用mono或者开启Development必然闪退,可以保证release版没问题。
页:
[1]