iOS build crashing on scene load

Hey guys,

I’ve been pulling my hair out over this issue for about 2 months now. My game is crashing only on an iOS build when attempting to load in a new scene. When running in the editor, all scenes work just fine, no warnings or errors.

When going from the main menu to my first level, the game crashes when I try to load a scene that has my gameplay logic (empty scene load just fine). What’s odd is if I set my first level as the initial starting scene rather than the main menu, it works just fine (until it tries to load level 2).

In the Xcode debugger I can see some Debug.Log() statements from some of my game logic being called as the new scene starts, so I know the scene is being loaded somewhat successfully but it crashes/freezes before the new scene appears. I don’t think it’s a memory issue, as the game only uses 1Gb of ram, but I could be wrong.

My question is, how can I narrow it down to what game logic code is causing the issue?

Xcode is reporting the game is crashing after calling this function:
UnityFramework`il2cpp::vm::LivenessState::AddProcessObject:

with this being the cause:
AssetGarbageCollectorHelper (7): EXC_BAD_ACCESS (code=1, address=0x135)

Some things I’ve tried:

  • Backtrace.io (doesn’t yield any significant insight)
  • Deleting the library folder
  • Using scene index number rather than scene string name
  • Upgrading Unity (was using 2022.3.16f1)
  • Disabling “Strip Engine Code”
  • Disabling “Use Incremental GC”
  • Manually setting “Always embed swift standard libraries” to “Yes” in Xcode
  • Manually adding “GameKit” to linked libraries in Xcode

I’m using Unity 2023.2.10f1
Xcode 15.2
testing device: iPad Pro 10.5 (2017) iPadOS 17.3.1
testing device 2: iPhone 7+ (2016) iOS 15.3

Any guidance on this would be greatly appreciated.

Hey guys,

After days of meticually going through the code I found the answer. It was because I was using GameObject.Find() and I guess it was causing some kind of race condition.

Lesson learned, don’t use GameObject.Find() in Awake or Start if possible.

Remember the first rule of GameObject.Find():

Do not use GameObject.Find();

More information: https://starmanta.gitbooks.io/unitytipsredux/content/first-question.html

More information: https://discussions.unity.com/t/899843/12

In general, DO NOT use Find-like or GetComponent/AddComponent-like methods unless there truly is no other way, eg, dynamic runtime discovery of arbitrary objects. These mechanisms are for extremely-advanced use ONLY.
If something is built into your scene or prefab, make a script and drag the reference(s) in. That will let you experience the highest rate of The Unity Way™ success of accessing things in your game.

“Stop playing ‘Where’s GameWaldo’ and drag it in already!”

1 Like