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??
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.
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?
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
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?
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.
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.
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)
Yeah... Jaap is right..it can be simply done by adding a plane with desired texture and setting it as child of camera ,where ever camera moves it follows. But I also liked the way Duck suggested for me its new approach i ll definitely use it some where.
The old method does’t work quite well in Unity 5. To apply the same effect, you’ll need Sprite with your camera.
Create a new camera (GameObject > Camera), and name it “Background Camera”.
Create a new Sprite (GameObject → 2D Object → Sprite), 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”.
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.
Now select your Background Camera in the hierarchy, and adjust these settings in the inspector:
Un-Check Flare Layer and Audio Listener and GUILayer (Legacy in Unity 5)
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”
Set Depth to 0
Click its culling mask setting, and un-check “Background Image”. This should result in the culling mask displaying as “Mixed …”
To use my image as texture for the sprite I needed to select the Texture and choose "Sprite (2D and UI)" as Texture Type in the Inspector. Took me quite some time, I just started playing around with Unity.
that works perfectly. thanks so much!
– tantorrrrCan somebody please lock this up? People keep bumping it. :|
– static_cast