Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Ufimsev · Jun 04, 2015 at 09:18 PM · c#camerajavascript

Visibility of objects

Hello. How to define visibility of object. For example as on a screen the cube behind a green wall has to be defined as invisible. Something such is used in the Occlusion Culling technology. alt text

Comment
Add comment · Show 3
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 tanoshimi · Jun 04, 2015 at 09:19 PM 1
Share

Your question is confusing. If your camera is placed where the green arrow is, the cube would be invisible, because there's a green wall in the way...?

avatar image instruct9r · Jun 04, 2015 at 09:22 PM 1
Share

Just to add to @tanoshimi's answer.... And you won't see the cube get's invisible in the editor, because Occlusion Culling works on the actual build of the game. So even if you do see the cube in the Editor, when you play, it will be invisible when you build the game and the camera is at that position. So you don't have to hide it manually...

avatar image Ufimsev · Jun 05, 2015 at 03:15 AM 0
Share

@tanoshimi The camera is located where the cut-off cone. The camera looks at a green wall. She sees a green wall, but doesn't see a white cube as it is blocked by a green wall. I need a script, whether which would define the object is covered with other object. At once I will tell: Raycast not an exit as objects have no colliders.

3 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by tanoshimi · Jun 05, 2015 at 07:41 AM

With the information in your further comments, it sounds like you want OnWillRenderObject: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnWillRenderObject.html

Call that function in a script attached to the cube and it will tell you which cameras will render it. If the function doesn't get called for a particular camera, the object is "invisible" to that camera.

Comment
Add comment · Show 4 · 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 Ufimsev · Jun 05, 2015 at 08:13 AM 0
Share

Unfortunately not, this function is also caused even when one object of overlap by another. The same problems at the OnBecameVisible() function.

avatar image Ufimsev · Jun 07, 2015 at 09:14 AM 0
Share

@tanoshimi Unfortunately not, this function is also caused even when one object of overlap by another. The same problems at the OnBecameVisible() function.

avatar image tanoshimi · Jun 07, 2015 at 09:15 AM 0
Share

(please don't post comments as answers).Ok, it sounds like you'll need to add colliders and use regular raycasting then.

avatar image Cherno · Jun 07, 2015 at 09:55 AM 0
Share

Give them colliders and set them to IsTrigger if you don't want them to block physics-based objects, such as rigidbodies. Trigger colliders will still register RayCasts.

avatar image
1

Answer by AmbroiseRabier · Mar 04, 2018 at 01:38 PM

tanoshimi answer helped me. You cannot made it with OnBecameVisible and OnBecameInvisible, because they get called only when the objects change visibility, that they are many or one camera having the object in view do not change anything. OnWillRenderObject are only called on gameobject having a renderer attached. (childrens do not counts). I tested it with occlusion culling (don't forget you have to bake it in Unity in the occlusion culling panel) and it work. In case you are moving the MeshRenderer you have a checkbox 'Dynamic Occluded' that should be setted to true (only beginning from unity 2017.2, on version bellow it is by default true).

This bellow is WIP, but should help understanding:

         private List<Camera> cameraSeeingMe;
         private Array<Camera> cameraSeeingMeBuffer;

         private void OnWillRenderObject() {
             // OnWillRenderObject is called even when editor pause, better avoid duplicate
             if (!isRenderingMe.Exists((e)=> e == Camera.current))
                 cameraSeeingMe.Add(Camera.current);
         }
         
         private void Update() {
             cameraSeeingMeBuffer = cameraSeeingMe.ToArray();
             cameraSeeingMe.Clear()
         }
         
         public bool isSeenBy(Camera cam) {
             foreach (var otherCam in cameraSeeingMe) {
                 if (cam == otherCam ) {
                     return true;
                 }
             }
             return false;
         }

You can add a gizmo to see what happen. We use the buffer because OnDrawGizmos get called immediately after OnWillRenderObject, and not after Update. (without buffer some gizmos won't be draw on some camera)

         private void OnDrawGizmos() {
             Gizmos.color = Color.yellow;
             foreach (var cam in cameraSeeingMeBuffer) {
                 Gizmos.DrawLine(transform.position, cam.transform.position);
             }
         }

[Edit]: Few corrections after more testing.

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 knudsjef · Jun 08, 2015 at 07:40 AM

You could make a bool called Visible or something and then use a raycast and see if anything is in the way. If it is, Visible = false; Else Visible = true;

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I want to put main camera floating 0 Answers

Animated camera problems 0 Answers

WorldToScreenPoint 0 Answers

Please Help me converting this to C# 3 Answers

Natural camera sway 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