Here I dump notes and snippets of code that could be generally useful to copy or reference in new projects.
- Set an
Application.targetFrameRate
because it can sometimes default to 30 and make a game feel bad, even on more powerful devices (e.g. observed on an iPhone 11)- Note that
QualitySettings.vSyncCount
takes precendence on some platforms. The docs explain things well
- Note that
- You probably want to set
Screen.sleepTimeout
(e.g. toSleepTimeout.NeverSleep
) because the default inactive sleep time can be very short on some devices (e.g. observed on an old Android) - Use TextMeshPro instead of the legacy Text components
- Each time you update the TextMeshPro package, you should also re-import the TMPro Essentials.
- Although re-import supposedly works on top of existing files, I've encountered issues with that before (where files were split into different folders and lookups failed). Consider deleting the current essentials and doing a clean import.
- Check "Bottom" in "Project Settings > Player > iOS > Other Settings > Defer system gestures on edges"
- Otherwise the home indicator on some iPhones will be too easy to activate
- Counter-intuitively, you must leave the "Hide home button on iPhone X" option unchecked, as this enables a different (undersired) behaviour, where the home indicator isn't visible until touched, but then still too easy to activate (in spite of the "Defer system gestures on edges" setting)
- Disable "Project Settings > Player > Android > Resolution and Presentation > Render Over Native UI"
- Otherwise some devices will have their OS visible behind the game
- Debug logging on Windows (with git bash):
- You'll probably need to change the editor version
cd "/c/Program Files/Unity/Hub/Editor/2020.2.1f1/Editor/Data/PlaybackEngines/AndroidPlayer/SDK/platform-tools"
./adb.exe logcat -s Unity
# or if you've got JAVA_HOME set up using a Unity Android player:
"$JAVA_HOME/../SDK/platform-tools/adb.exe" logcat -s Unity
- "File"/other persistent changes are synced to the browser's indexed DB, but (by default) only when Unity internally thinks it should sync it. This means you can successfully write a file, and then exit the application, and that write can be lost.
- See this StackOverflow Q&A for a solution
- This has also been solved in MyLibrary.KVS
- If using CloudOnce:
- When installing for the first time, be sure to switch to the PC platform to avoid a
GooglePlayServices
missing exception. From there, you can update the External Dependency Manager (at the bottom of the Assets menu) and then switch to Android. - The External Dependency Manager seems to ignore the Android SDK that's linked to Unity's preferences, and uses
JAVA_HOME
instead. - Changes to
JAVA_HOME
aren't picked up by the External Dependency Manager even after restarting Unity. I restarted my entire PC for this to work.
- When installing for the first time, be sure to switch to the PC platform to avoid a