
Unity ScriptableObject Bug: Data Resetting During Play Mode
February 11, 2026
Unity Mouse Position Bug: Incorrect Screen-to-World Coordinates (Causes and Fixes)
February 13, 2026A common issue in mobile Unity projects happens when rotating the device causes the app to freeze, restart, lose references, or even crash completely. Many developers describe this as a “Unity Android orientation bug.”
In reality, screen rotation on Android can trigger complex lifecycle changes. If your project is not prepared for those changes, problems appear quickly.
This article explains why screen rotation can cause crashes and how to prevent orientation-related issues in Unity Android builds.
Why Screen Rotation Is Risky on Android
On Android, changing device orientation may cause the activity to restart. When that happens:
- The app may reload the scene
- Static variables may reset
- Singletons may duplicate
- References may become null
- Native plugins may reinitialize incorrectly
If your code assumes the app never reloads, crashes can happen.
Common Scenario 1: Activity Restart on Rotation
By default, Android may destroy and recreate the activity when orientation changes.
This means your Unity app can partially restart.
Symptoms include:
- Game restarts unexpectedly
- Black screen after rotation
- Missing references
- Duplicate persistent objects
Common Scenario 2: DontDestroyOnLoad Duplicates
If you use a singleton pattern like this:
public class GameManager : MonoBehaviour
{
public static GameManager Instance;
void Awake()
{
if (Instance == null)
{
Instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
Destroy(gameObject);
}
}
}
Orientation-based restarts can cause unexpected duplicate creation if not handled carefully.
Sometimes the original instance still exists, and the system attempts to create another.
Common Scenario 3: Native Plugin Crashes
If your project uses:
- Ad SDKs
- Firebase
- Camera plugins
- AR systems
These plugins may not handle orientation changes correctly and crash during reinitialization.
Common Scenario 4: UI Breaking After Rotation
After rotation, UI may:
- Resize incorrectly
- Lose layout structure
- Stretch or overlap
This is usually caused by incorrect Canvas scaling settings.
How to Prevent Orientation Crashes
1. Lock Orientation If Not Needed
If your game does not require rotation, disable it.
Go to:
- Player Settings → Resolution and Presentation
- Set Default Orientation (Portrait or Landscape)
- Disable Auto Rotation
This is the simplest and safest solution.
2. Configure Auto Rotation Properly
If rotation is required:
- Enable only supported orientations
- Avoid enabling all four unless necessary
Reducing allowed orientations reduces unexpected transitions.
3. Handle Resolution Changes
You can detect screen size changes:
void Update()
{
if (Screen.width != lastWidth || Screen.height != lastHeight)
{
Debug.Log("Screen size changed");
lastWidth = Screen.width;
lastHeight = Screen.height;
}
}
This allows you to refresh UI or reposition elements safely.
4. Use Proper Canvas Scaling
Set Canvas Scaler to:
- UI Scale Mode: Scale With Screen Size
- Reference Resolution set appropriately
This prevents layout breaking during rotation.
5. Avoid Heavy Initialization in Awake
If orientation restarts the activity, heavy initialization inside Awake can cause crashes or long freezes.
Move expensive initialization to controlled startup logic instead.
6. Test on Real Devices
Orientation behavior differs between devices and Android versions. Always test rotation on multiple real devices.
Advanced: Android Manifest Control
In advanced cases, you can modify the Android manifest to control configuration changes manually.
This prevents activity recreation on rotation.
However, this requires custom Android configuration and should only be done if necessary.
Debugging Orientation Crashes
If your app crashes on rotation:
- Check Android Logcat
- Look for NullReferenceException
- Check native plugin errors
- Test with plugins temporarily disabled
Many orientation crashes are plugin-related rather than Unity engine issues.
Is This a Unity Bug?
Usually not. Android lifecycle behavior is responsible for most orientation problems. Unity responds to those system-level changes.
Crashes happen when scripts or plugins are not prepared for activity recreation.
Best Practices Summary
- Lock orientation if possible
- Use proper Canvas scaling
- Handle resolution changes safely
- Avoid fragile singleton logic
- Test on multiple Android devices
Conclusion
The Unity Android orientation “bug” is usually a lifecycle management issue. Screen rotation can restart or reconfigure the app, which breaks poorly structured systems.
By controlling orientation settings, structuring singletons safely, and testing on real hardware, you can eliminate most crashes related to rotation.
Understanding Android’s behavior is key to building stable Unity mobile applications.










