我的场景有一些基本的火焰效果。它的最大粒子数为20,并且屏幕上同时激活的实例不超过4-5个。我甚至检查过分析器,但内存使用量最多约为150 MB。
鉴于这些,编辑器中的所有运行都很好,但是一旦粒子变得可见,游戏就会在每次运行时崩溃。我在虚拟Nexus平板电脑上进行了测试。我使用的是Unity 2017.1.1。
内置游戏也在PC上崩溃(使用相同的PC为PC制作最终版本)。奇怪的是,我展示的代码运行良好。它只是从MeshFilter
获取网格,将其作为发射器添加到粒子系统。由于这发生在Awake
并且级别实际开始运行,因此代码不会出错。问题是只有在粒子系统上实际使用网格时才会出现问题。
我能够将问题追溯到以下几行:
var mf =
transform.parent.gameObject.GetComponentFromParentRecursive<MeshFilter>();
if (mf != null && mf.mesh != null)
{
var sh2 = system.shape;
sh2.mesh = mf.mesh;
return;
}
public static class GetComponentRecursive
{
/// <summary>
/// Returns the first Component (T) found on the parent or its children
/// = the gameobjects on the same level as this is called on.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="g"></param>
/// <returns></returns>
public static T GetComponentFromParentRecursive<T>(this GameObject g)
where T : Component
{
if(g.transform.parent.GetComponent<T>() != null)
{
return g.transform.parent.GetComponent<T>();
}
else
{
foreach (Transform c in g.transform.parent.transform)
{
if(c.GetComponent<T>() != null)
{
return c.GetComponent<T>();
}
}
}
return null;
}
}
请记住GetComponentFromParentRecursive
有效,可以将它用于精灵,不会造成伤害。当我注释掉前几行时,它不会崩溃(只是丢失了功能)。
为什么会导致崩溃的任何想法?并且只在建造的游戏中?
修改
当Unity
过滤器被禁用时,我想我可能会得到一些东西。它有NullPointerException
和大量W/ResourceType: No package identifier when getting name for resource number
。
09-08 11:11:49.976 922-922 /? W / ResourceType:获取资源号0x0000001b的名称时没有包标识符 09-08 11:11:49.995 13409-13409 /? D / ActivityThread:SVC创建服务:CreateServiceData{token=android.os.BinderProxy@42549900 className = com.google.android.gms.udc.service.UdcApiService packageName = com.google.android.gms intent = null} 09-08 11:11:49.998 922-927 /? D / dalvikvm:GC_CONCURRENT释放2918K(32059),32%免费6993K / 10216K,暂停8ms + 6ms,总计74ms 09-08 11:11:50.006 13409-13409 /? D / ActivityThread:SVC-CREATE_SERVICE处理:0 / CreateServiceData{token=android.os.BinderProxy@42549900 className = com.google.android.gms.udc.service.UdcApiService packageName = com.google.android.gms intent = null} 09-08 11:11:50.010 13409-13409 /? D / ActivityThread:SVC-BIND_SERVICE处理:0 / BindServiceData{token=android.os.BinderProxy@42549900 intent = Intent {act = com.google.android.gms.udc.service.START pkg = com.google.android.gms }} 09-08 11:11:50.022 186-186 /? W / MALI:MTK_AUX_isMTKFormat:168:int MTK_AUX_isMTKFormat(ANativeWindowBuffer_t *):format = 1 09-08 11:11:50.024 819-819 /? V / WallpaperService:com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0中的可见性更改:1 09-08 11:11:50.025 819-819 /? V / WallpaperService:onVisibilityChanged(true):com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0 09-08 11:11:50.025 819-819 /? V / WallpaperService:com.android.phasebeam.PhaseBeamWallpaper$RenderScriptEngine@41e525e0中的偏移量变化:0.5,0.5 09-08 11:11:50.031 922-922 /? D / AbsListView:onWindowFocusChanged:hasWindowFocus = true,this = android.widget.ListView {4206ddb8 V.ED.VC. ...... ID 0,176-576,176#7f0e0046 app:id / digital_appwidget_listview} 09-08 11:11:50.032 710-710 /? D / PhoneStatusBar:setSystemUiVisibility vis = c0000700 mask = ffffffff oldVal = 700 newVal = c0000700 diff = c0000000 09-08 11:11:50.034 710-710 /? D / BarTransitions.PhoneStatusBarView:MODE_OPAQUE - &gt; MODE_TRANSLUCENT animate = false 09-08 11:11:50.036 186-307 /? I / BufferQueue:com.android.phasebeam.PhaseBeamWallpaper [queue] fps:0.05,dur:39249.01,max:39171.83,min:77.18 09-08 11:11:50.037 186-186 /? I / BufferQueue:com.android.phasebeam.PhaseBeamWallpaper [release] fps:0.05,dur:39239.19,max:39160.33,min:78.86 09-08 11:11:50.039 17428-17440 /? V / SurfaceView:this = vjd {42785900 V.E ..... ...... ID 0,0-1280,720}调整大小:w = 1280 h = 720,cur w = -1 h = -1 09-08 11:11:50.040 710-710 /? D / BarTransitions.PhoneStatusBarView:applyModeBackground oldMode = MODE_OPAQUE newMode = MODE_TRANSLUCENT animate = false 09-08 11:11:50.042 710-710 /? D / BarTransitions.NavigationBarView:MODE_OPAQUE - &gt; MODE_TRANSLUCENT animate = true 09-08 11:11:50.042 710-710 /? D / BarTransitions.NavigationBarView:applyModeBackground oldMode = MODE_OPAQUE newMode = MODE_TRANSLUCENT animate = true 09-08 11:11:50.042 13409-13559 /? D / SQLiteDatabase:beginTransaction() 09-08 11:11:50.047 922-922 /? V / InputMethodManager:onWindowFocus:com.android.launcher3.AppsCustomizeTabHost {42312918 VFE ..... .F ....我。 0,0-1280,800#7f10002b app:id / apps_customize_pane} softInputMode = 288 first = true flags =#d910100 09-08 11:11:50.048 922-922 /? V / InputMethodManager:START INPUT:com.android.launcher3.AppsCustomizeTabHost {42312918 VFE ..... .F ....我。 0,0-1280,800#7f10002b app:id / apps_customize_pane} ic = null tba=android.view.inputmethod.EditorInfo@4234f6e8 controlFlags =#105 09-08 11:11:50.049 641-908 /? V / InputMethodManagerService:windowGainedFocus:android.os.BinderProxy@42823bf0 controlFlags =#105 softInputMode =#120 windowFlags =#d910100 09-08 11:11:50.050 710-964 /? D / KeyguardViewMediator:isInputRestricted:shows = false,needReshow = false,provisioned = true 09-08 11:11:50.051 641-908 /? W / InputMethodManagerService:得到RemoteException向pid发送setActive(false)通知3549 uid 10097 09-08 11:11:50.054 922-922 /? W / ResourceType:获取资源号0x9c010303的名称时没有已知的包 09-08 11:11:50.057 922-922 /? W / ResourceType:获取资源号0x9c010104的名称时没有已知的包 09-08 11:11:50.058 922-922 /? W / ResourceType:获取资源号0x9c010204的名称时没有已知的包 09-08 11:11:50.059 922-922 /? W / ResourceType:获取资源号0x9c010304的名称时没有已知的包 09-08 11:11:50.060 922-922 /? W / ResourceType:获取资源号0x9c010404的名称时没有已知的包 09-08 11:11:50.060 831-842 /? W / Binder:从绑定器存根实现中捕获RuntimeException。 显示java.lang.NullPointerException 在android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280) 在com.android.internal.view.IInputMethod $ Stub.onTransact(IInputMethod.java:129) 在android.os.Binder.execTransact(Binder.java:404) at dalvik.system.NativeStart.run(Native Method) 09-08 11:11:50.060 831-842 /? W / System.err:java.lang.NullPointerException 09-08 11:11:50.060 922-922 /? W / ResourceType:获取资源号0x9c010504的名称时没有已知的包 09-08 11:11:50.060 831-842 /? W / System.err:在android.inputmethodservice.IInputMethodWrapper.setSessionEnabled(IInputMethodWrapper.java:280) 09-08 11:11:50.061 831-842 /? W / System.err:at com.android.internal.view.IInputMethod $ Stub.onTransact(IInputMethod.java:129) 09-08 11:11:50.061 831-842 /? W / System.err:在android.os.Binder.execTransact(Binder.java:404) 09-08 11:11:50.061 831-842 /? W / System.err:at dalvik.system.NativeStart.run(Native Method) 09-08 11:11:50.061 922-922 /? W / ResourceType:获取资源号0x9c010604的名称时没有已知的包 09-08 11:11:50.062 186-1008 /? I / BufferQueue:StatusBar [queue] fps:1.18,dur:1693.94,max:991.08,min:702.86 09-08 11:11:50.066 13409-13559 /? D / SQLiteDatabase:endTransaction() 09-08 11:11:50.068 922-922 /? D / ListView:measureHeightOfChildren adapter=android.widget.RemoteViewsAdapter@41f35008,startPosition = 0,endPosition = -1,maxHeight = 121,this = android.widget.ListView {4206ddb8 V.ED.VC. ...... ID 0,176-576,176#7f0e0046 app:id / digital_appwidget_listview} 09-08 11:11:50.069 186-186 /? I / BufferQueue:StatusBar [release] fps:1.18,dur:1692.43,max:989.53,min:702.90 09-08 11:11:50.070 186-1083 /? I / BufferQueue:NavigationBar [queue] fps:0.03,dur:39424.04,max:39424.04,min:39424.04 09-08 11:11:50.071 710-710 /? D / PhoneStatusBar:状态栏WINDOW_STATE_SHOWING 09-08 11:11:50.078 922-922 /? D / Launcher3:AppsCustomizePagedView,onMeasure mIsInEditMode = false1073743104 1073742535 1280 711 09-08 11:11:50.079 922-922 /? W / ResourceType:获取资源号0x00000001
的名称时没有包标识符
答案 0 :(得分:0)
它不起作用的原因是,在MeshFilter
以及粒子系统的Emission Shape
上,不能使用 - 没有明显的理由 - 相同的网格(通过引用相同)。为此我必须像这样制作完整的副本:
if (mf.mesh.isReadable)
{
Mesh myAwesomeNewMeshForNoApparentReason2 = new Mesh();
myAwesomeNewMeshForNoApparentReason2.Clear();
myAwesomeNewMeshForNoApparentReason2.name = mf.gameObject.name + "_NewMesh";
myAwesomeNewMeshForNoApparentReason2.vertices = mf.sharedMesh.vertices;
myAwesomeNewMeshForNoApparentReason2.triangles = mf.sharedMesh.triangles;
myAwesomeNewMeshForNoApparentReason2.uv = mf.sharedMesh.uv;
var sh2 = system.shape;
sh2.mesh = myAwesomeNewMeshForNoApparentReason2;
return;
}
确保对象未标记为static
。这样我就能让它发挥作用。