Forum rules - please read before posting.
Tech questions during the weekend? Drop in on the community Discord channel!

Fit Unity UI into Forced Aspect Ratio

When you're using a forced aspect ratio, AC automatically fits legacy Unity GUI menus to the adjusted screen bounds. For Unity UI you can use this script:

To use it, create a Unity UI Canvas with a Panel that stretches over the entire screen (Rect Transform: Stretch in all directions, Left/Top/Right/Bottom all zero) and add the script to it. Then add the actual menu elements as children of this panel. 


  • Great solution!
  • @ChrisIceBox is this something that'll be a custom script or an addition to AC's future?
  • Chris - Please feel free to take whatever you want of the script to put into AC if you like.
  • edited May 2016
    Hi! Sound like cool stuff, but will this work on the Dialogue system's UGUIs, I mean when working in tandem with AC? or is there something else one needs to do for DS's GUIs to fit the screen properly in that case?

    PS: never mind... it's in the manual.
  • edited May 2016
    BTW, the Bolt Riley developer pointed out that FitUIToAspectRatio.cs didn't accommodate Canvas Scalers. I updated the script in the Dialogue System's Adventure Creator package. If you don't use the Dialogue System, change your Fit() method to:

    void Fit() {
      if (mainPanel == null) {
        Debug.LogError("Assign Main Panel", this);
      var rect = AC.KickStarter.mainCamera.LimitMenuToAspect(new Rect(0, 0, Screen.width, Screen.height));
      var scale = (m_canvasScaler != null) ? m_canvasScaler.referenceResolution.x / Screen.width : 1;
      mainPanel.sizeDelta = new Vector2(scale * -2 * rect.x, scale * -2 * rect.y);

  • edited June 2018
    I'm probably doing something wrong, but when I use this it just moves my UI to the start of left side of the new aspect ratio so that it overflows on the right side. What I want is for it to shrink or expand to fit the forced aspect ratio in all screen sizes.
  • Hi! Is your Canvas set to stretch in all directions? Are you using the Canvas Scaler fix above? This is over 2 years old. I honestly don't know if Chris has already implemented something like this or better into AC itself. If both of those things look OK and you're still stuck, let me know whether you're using the Dialogue System or not, and what your Canvas setup is like.
  • AC does now support Unity UI position-limiting under certain conditions.

    What's your Menu's Position type?  Without the script, have you checked Always fit within screen? and defined your RectTransform boundary?
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.
Do NOT follow this link or you will be banned from the site!