Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
9
Question by Mattivc · May 22, 2010 at 01:18 AM · camerafpsrenderer

Always render a object on top of another.

Is it possible to make a object always render on top of another even if there is another object between it and the camera. Like making the gun in a FPS always render on top even if it goes trough a wall.

Im preferably looking for a way to do this with the standard version of unity, and not use any pro-only features.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

8 Replies

· Add your reply
  • Sort: 
avatar image
63
Best Answer

Answer by spinaljack · May 22, 2010 at 01:27 AM

Best solution is to place a second camera on the scene and put the gun in front of the other camera, set the gun to a layer of it's own and make the second camera only render the gun layer, set the camera to a higher depth than the main camera so that the gun renders over the main view and set it to depth cull so that it doesn't completely hide the main camera.

The result is that the gun will always appear above everything else. If you wanted to have the gun get shaded by lights near the player you can place the second camera as a child of the main camera so that the gun and camera move around with the player.

Comment
Add comment · Show 15 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spinaljack · May 22, 2010 at 01:28 AM 0
Share

This is also how I render special HUD elements like way point arrows and $$anonymous$$imaps.

avatar image Wiplash · Aug 22, 2011 at 02:14 PM 0
Share

Hi there,

I am trying to set this up but my secondary camera seems to be covering the main one. As far as I can see I have set it to only render one layer and also it has culling on to $$anonymous$$imum distance. Have you any idea what I am doing wrong?

avatar image Edyvargas · Oct 25, 2011 at 07:32 AM 13
Share

The second camera must be a child of the main camera and must have "mouse look" too.

On the Second Camera:

  • Clear Flags = Depth Only

  • Culling $$anonymous$$ask = "New Layer Only"

  • Depth = 1

  • The rest as default

On the $$anonymous$$ain Camera:

  • Culling $$anonymous$$ask = Everything except the new layer

...perhaps this can help you.

avatar image onexdrk Edyvargas · Oct 12, 2019 at 03:35 PM 0
Share

Also looks like you need to select Clear Flags: Don't Clear for child camera

avatar image Jaqal · Dec 15, 2014 at 12:39 AM 1
Share

Will you still receive dynamic shadows with this method? I have never gotten it to work with two cameras.

avatar image SummitJain Jaqal · Nov 30, 2015 at 11:40 AM 1
Share

yes you will receive dyanamic shadows as your layer is default and should provide shadows of the object in the scene.

avatar image GigaRoid · Apr 28, 2015 at 04:32 PM 3
Share

There has to be some way to create a special rendering order, one layer before another. That's how they programmed it, shouldn't we have access to it being, you know, developers?

Show more comments
avatar image
2

Answer by osamansr2o1oo · Sep 20, 2018 at 10:33 AM

in case anybody didn't get the accepted answer !
***Edyvargas simplified it in a comment on the accepted answer check his comment***
Clear Flags = Depth Only
Culling Mask = "New Layer Only"
Depth = 1
On the Main Camera: Culling Mask = Everything except the new layer

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Mr-Jun · Jan 30, 2017 at 10:48 AM

This idea looked intimidating at first, but its actually super simple. Thanks for the answer. Yes, still usefull in 2017 :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image danksky · Jun 12, 2017 at 08:16 PM 1
Share

How can this be applied to a S$$anonymous$$mVR CameraRig?

avatar image
0

Answer by ChrisRede · Feb 04, 2020 at 06:41 PM

Works also on 2019.1.0f2 and with VR! Nice Thanks!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fahruz · Jul 06, 2021 at 11:46 AM 0
Share

How did you make it work in VR? I did exactly as the instructions above, but my object in its dedicated layer isn't rendering.

avatar image
0

Answer by samf1111 · Aug 18, 2020 at 08:53 PM

you could set the shader to 'text.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Lerping Field Of View is buggy 1 Answer

How can I stop the drawcall of an object if it is not in view of the camera, without using occlusion culling? 1 Answer

Massive FPS hit when changing colors on the fly 3 Answers

C# Renderer.IsVisible counts when editor camera sees object 0 Answers

How to get the camera to hold the gun? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges