Forum rules - please read before posting.

Background Constraint Shortcomings

I'm hoping there is a solution or perhaps I can request a new feature to handle the issue I'm having with background constraints.

As we know, there are multiple ways to constrain the camera to the background, but the easy way (Aspect ratio: Fixed) really limits how your game will look on various device aspect ratios. What I mean by "how your game looks" is the fact that you are left with black bars on the edges of very wide devices and letterboxes on iPad devices.

To keep this simple, let's assume a background (bg) size of 3680 x 2048. I want to my images under 2048 on both sides so I would most likely spit this up into 2 images of 1840 x 2048 and put them together in Unity under _SetGeometry. If I had a very wide bg I might even have 3 or 4 images of this size aligned together.

If I enable Constrain in Horizontal movement of the NavCam and set the Min and Max constraints it will work great for 1 aspect ratio. So if I set it up for iPad, and then switch to iPhone 12, the constraints no longer work well and I'm able to see too much past my edges.

If I use a Background constraint image instead of setting the Min and Max values, then the camera is constrained fine for every aspect ratio which is great, BUT, I have to use a 3680 x 2048 image which defeats the purpose of staying under 2048.

If I wanted a really wide background say equivalent to 7360 x 2048. Yikes. Now, I could break this up into 4 pieces and use the Fixed aspect ratio feature but I'm back to those black bars I don't want. I could also use a separate 7360 x 2048 image, crush/compress it down as small as possible and turn it off in the inspector and just use it for the constraint but that seems just as bad if not worse.

Sooooo, my question is, am I missing something, or do I have some other options? Is there not a way we could create a constraint boundary with geometry or a game object and have it respect this as the camera bounds? This way it remains the same for any aspect ratio.

I appreciate any help.


  • Welcome to the community, @TimMakesGames.

    What's assigned as the GameCamera2D's "Background constraint" doesn't necessarily need to be the same sprite as the visible background. It can be a separate sprite, and can have its "Sprite Renderer" component unchecked to make it invisible.

    So long as its boundary covers the playable area, you can rely on it and unenforce your game's aspect ratio. Even a 1x1 pixel sprite should work. Just use Unity's Rect Transform gizmo in the top toolbar to stretch it out to match your background, assign it as the constraint, disable its Sprite Renderer component, and you should be good to go.

  • Hi Chris,

    Wow, the one thing I didn’t try - resizing the sprite with the transform.

    Thanks for the tip, I’ll give it a try as soon as I get some sleep :)
  • Finished testing this. In case anyone else comes across the same need, the suggestion from Chris about using a small sprite and scaling it to the bounds of the background seems to be working well for me. Yay!

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.