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
5
Question by sbertout · Mar 29, 2011 at 12:11 AM · cameraeditorsceneignoreonbecamevisible

On can I have OnBecameVisible/Invisible ignore the scene/editor camera and only work for the game camera ?

everything is in the title.. I just want to avoid checking if my object is visible in my update function (so every frame) and would like to use unity's OnBecame * functions for that But unfortunately it doesn't work from the editor

any idea ? thanks in advance !

Comment
Add comment · Show 4
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 Justin Warner · Mar 29, 2011 at 12:32 AM 0
Share

Can you rephrase the question please? I don't understand it... Sorry.

avatar image Jason B · Mar 29, 2011 at 12:57 AM 0
Share

He seems to be saying that he wants some way to tell when his objects leave the view of his main camera, but not in-game; Through the editor.

avatar image Justin Warner · Mar 29, 2011 at 01:19 AM 0
Share

Oh... seems a little pointless, but thanks for the clarification lol.

avatar image sbertout · Mar 29, 2011 at 04:54 AM 0
Share

yeah looks like I've typed a bit too fast.. basically I want to use OnBecameInvisible/Visible (in order to automatically kill/respawn my gameobject, so I can't really use OnWillRenderObject ins$$anonymous$$d..) the issue is that the scene/editor camera is also used for that (not only the game camera) I was wondering if there's a way to fix that it's really annoying actually because the game behaves differently when played in the editor than when played as a standalone I'm sure this would beneficial to a lot of people if this was fixed on the unity side (what about a project option somewhere?) cheers

6 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by nomadic · Dec 03, 2014 at 04:35 PM

Here's what I've been doing:

 void OnBecameVisible()
 {
     #if UNITY_EDITOR
     if (Camera.current.name == "SceneCamera") 
         return;
     #endif
     // put your code here
 }
Comment
Add comment · Show 3 · 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 xuqiujing · Mar 08, 2016 at 02:56 AM 0
Share

It dose not work. If one gameObject is visible by gameCamera both in Scene and Game, OnBecameVisible() will be called twice.

avatar image slake_it · May 13, 2016 at 09:09 PM 0
Share

it works for me

(not perfectly, since the events don't always get called from the game camera if the scene view is visible), but it works if you are displaying only the game view

Thanks

avatar image slake_it · Jul 04, 2018 at 12:25 PM 0
Share

Thanks for the great solution

avatar image
0

Answer by Bunny83 · Mar 29, 2011 at 03:29 AM

I had some similar issues with AnimateOnlyIfVisible. You can't watch your object not being animated because at the moment any camera sees it, it will animate. Unfortunately as far as i know there's no way to go around that.

The only thing you can try is not using OnBecameVisible but Camera.OnWillRenderObject. OnWillRenderObject is a message that is sent by the camera to your object. I'm not sure if this is called camera independently, but as far as i can tell you should be able to sort out which camera is rendering the object. Just check Camera.current if that's your desired camera or not.

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 el_santo · Apr 08, 2015 at 08:48 AM

I see only one way:

if UNITY_EDITOR

  public void FixedUpdate()
  {
      if (MyFunctionIsObjectVisible(transform.position))
          FireOnBecameVisible();
  }

else

  protected void OnBecameVisible()
  {
      FireOnBecameVisible()
  }

endif

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 TimNick151297 · Feb 27, 2016 at 03:58 PM

A different solution is just to specify the camera with a tag. For example:

 function Update () {
 
     if (Camera.current.tag == "MainCamera")
 
         {
 
             if (this.GetComponent.<Renderer>().isVisible == false)
 
                 {
 
                     //do something
 
                 }
 
         }
 
 }

Note that this only works in fullscreen playmode, not minimized view.

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 Khaled_A_Younes · Dec 28, 2016 at 11:59 AM

This is answer is probably long overdue, but the solution that worked for me was to close the scene view tab.

Unity docs has this to say about OnBecameInvisible:


Note that object is considered visible when it needs to be rendered in the scene. It might not be actually visible by any camera, but still need to be rendered for shadows for example. Also, when running in the editor, the scene view cameras will also cause this function to be called.


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

8 People are following this question.

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

Related Questions

Editor Camera Orthograpric Control 5 Answers

Problem accessing the scene camera 1 Answer

Modify SceneCamera's position in script? 2 Answers

Drawing Handles 1 Answer

Camera behavior the same as the unity editor has 2 Answers


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