x


How can I display a flat background - 2D image, not a skybox - behind everything in my camera?

hi,

I am working on a characted editor and I want to separate the scene from the background. the editor has got different views and I need the same background in any of them. my idea was to simply add a flat 2D image to the game camera background (whatever Im using each time). I thought it would be much easier but I cant find out how to do it properly.

the closest Ive been is having a camera for the game scene and then create a 2nd camera whith a skybox in a separate layer but I cant set it up as non depth camera.

in any case, is there any way to simply add a flat image as background no mather which camera, view, perspective I have??

Thanks a lot!!

more ▼

asked Jan 05 '10 at 12:33 PM

Luismi gravatar image

Luismi
215 8 9 16

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You're almost there, with the 2nd camera approach. Here's how to do it:

  • Create a new camera (GameObject -> Create Other -> Camera), and name it "Background Camera".

  • Create a new GUI Texture (GameObject -> Create Other -> GUI Texture), and name it "Background Image".

  • Click the "Layer" dropdown menu in the Background Image's inspector pane, and select "Add Layer".

  • In the next free "User Layer" slot, create a new layer name called "Background Image". This will be directly under the layer named "Terrain" if you haven't yet added any others.

  • Select your Background Image in the hierarchy, and give it the desired texture, and set the x, y, width and height under "Pixel Inset" so that it fills the screen appropriately.

  • Near the top of the inspector window, Use the layer dropdown menu to assign your "Background Image" layer that you defined earlier to this gameobject.

  • Now select your Background Camera in the hierarchy, and adjust these settings in the inspector:

    • Un-Check Flare Layer and Audio Listener (but leave GUILayer enabled)

    • Set Clear Flags to Solid Color

    • Set Depth to -1

    • Set Culling Mask, first to "Nothing", and then to "Background Image"

  • Now Select you other (main) camera, and in the inspector:

    • Set its Clear Flags to "Depth Only"

    • Click its culling mask setting, and un-check "Background Image". This should result in the culling mask displaying as "Mixed ..."

Voila, this should give you your GUI Texture rendered by your background camera, behind everything else rendered by your main camera. And for any other additional cameras (eg, other camera angles) that you want to use, just repeat the last two steps on them.

more ▼

answered Jan 05 '10 at 01:53 PM

duck gravatar image

duck ♦♦
41k 92 148 415

thanks for this Duck, I was looking for the same thing. Query though, is there anyway to stop the clipping for a full background image when aspect ratio is changed?

Mar 23 '10 at 12:31 PM RobF

It's much better if you set all the pixel inset values to 0, and set the scale to (1, 1, 1) instead. Otherwise, the background image doesn't adapt to different screen sizes. The only possible drawback is that the background image will get stretched or squished with different aspect ratios than the one you used to create the game. If this is not desirable, you can use a script like this one: http://www.unifycommunity.com/wiki/index.php?title=GuiRatioFixer

Apr 21 '10 at 11:16 PM Eric5h5

In 3.2, when I do all the above, the 'background' image is drawn really as a 'foreground' image in the Editor, all my other geometry behind the texture. I changed 'depth', no help. Anyone?

Feb 28 '11 at 09:21 PM DaveA

This solution works excellently. My only problem is when I go to actually make the background scroll, it stutters every now and then as it moves.

I am adding an offset*Time.deltaTime every update to the pixelInset.x. Is there a better way to make the background scroll? Code is below.

function Update () { var xVel : float = -xVelocity*Time.deltaTime; background1.pixelInset.x += xVel; background2.pixelInset.x += xVel; }

Aug 25 '11 at 05:06 PM paulg568

I had the same problem as DaveA. I finally realized that while my BG camera's culling mask was set correctly, my actual BG image was assigned to layer Default and not layer BackgroundImage.

That step is listed in the instructions but I must have accidentally skipped it or messed it up.

Feb 28 '12 at 04:51 AM AbePralle
(comments are locked)
10|3000 characters needed characters left

A very simple solution add a plane with background texture as child object to the camera so it will always keep the same position relative to the camera. Move the plane close to the 'far clipping plane' distance.

more ▼

answered Jan 05 '10 at 01:37 PM

Jaap Kreijkamp gravatar image

Jaap Kreijkamp
6.4k 20 26 70

Liked and used! A really fast way to set up a static background! (I would suggest a directional light too to make it look... brighter! :D)

Apr 11 '11 at 02:42 PM FrHaYwOrKs

Ist not the moste stable but the easyest background images setup, works fine for me.

May 17 '11 at 10:57 AM Malzbier
(comments are locked)
10|3000 characters needed characters left

in perspective view i have solid color for a BG. BG texture not working :/ why?

more ▼

answered Mar 16 at 06:28 PM

stepniu gravatar image

stepniu
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3000
x2197
x475
x258
x166

asked: Jan 05 '10 at 12:33 PM

Seen: 44715 times

Last Updated: Mar 16 at 06:28 PM