Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to put entire game in the safe area?

Discussion in '2D' started by ahcollin, Mar 17, 2022.

  1. ahcollin

    ahcollin

    Joined:
    Jan 12, 2016
    Posts:
    7
    I'm making a 2D game and I'm looking for help on how to make sure the entire game only displays in the safe area on both iOS and Android.

    There's no shortage of tutorials on how to put Canvas elements inside the safe area, but I'd like my entire game to fit in there. Is there an automatic way to do this in Unity? Or perhaps a way to set the camera bounds to the safe area? What's the best way?

    Thanks!
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    You could crop the main camera rect (in normalized coordinates!!) down appropriate to the safe area. Remember to layer another camera behind it (otherwise you'll have undefined graphics glitches behind around the borders).

    You could also try Cinemachine, as it has some stuff to set up with this, but it requires setup:

    https://forum.unity.com/threads/cinemachine-framing-with-screen-safearea.1079435/
     
  3. ahcollin

    ahcollin

    Joined:
    Jan 12, 2016
    Posts:
    7
    Thanks Kurt. But.. 2 separate cameras? I wonder why there's no easy way to do this in Unity? Seems like it would be an obviously useful feature. Unity already has all the safe area data, why not allow games to implement it easily. What am I missing here?
     
    RoaringHeart likes this.
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,954
    Methinks you overestimate the effort of two cameras.

    Make your camera rig like so:

    MyCameraRigWithNothingOnItWhatsoever
    MyFullscreenCameraSetToRenderNothingButBlack
    MyActualCameraThatMightBeSmallerInSafeAreaAndIsLayeredHigherUp[/code]
     
  5. RoaringHeart

    RoaringHeart

    Joined:
    May 25, 2021
    Posts:
    2
    Try disabling "Render outside safe area" if your building for Android. You can find it in the Player Settings under Resolution and Presentation. Although I wasn't able to find a similar feature for iOS.