Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 lightningmanic · Oct 06, 2015 at 02:13 PM · instantiateonbecamevisible

OnBecameVisible not working on Instantiated object

During the scene load, I instantiate a new GameObject from my Resources directory. (This loads the object just fine in my scene). I then add a component (script) with: obj.AddComponent<ScarabScript>();

In the script file, I know it's attaching correctly since the void Start() and void Update() both give output when I have debugging statements within them. However, the private void OnBecameVisible() function never triggers, even when the object is in clear view in the scene.

What's more odd is I have the exact same script (in a different file) setup for another object I Instantiate earlier in the New Scene function that works just fine. I can't figure out why it won't link up or ever trigger. Is there a better or alternative solution?

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

1 Reply

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

Answer by Kyle_WG · Oct 06, 2015 at 04:37 PM

If you're instantiating it, can you not use OnEnable(); or Awake(); functions to do your tasks? This function is relating to the rendering of the object and is worth noting that it is affected by all camers including the scene cameras. Not so sure you can rely on it being called if it's instantiated into view as it quite possibly doesn't call OnBecameVisible(); as it wasn't even alive yet.

Try putting it out of view and back in again to see if it's called then. If it does call then you might need to instantiate it off screen first or use the other methods.

I'm guessing it's the same setup as the one that does work but make sure that your script is attached to the same object as the renderer.

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 lightningmanic · Oct 08, 2015 at 05:37 PM 0
Share

Neither of these seemed to work. The object I'm instantiating is a .blend project file (scarab_beetle.blend). The other I tried is also a .blend project file (key.blend), and if I change the object from scarab_beetle to key, then everything works fine. This leads me to believe there might be something fishy with the import of my scarab_beetle.blend object...

avatar image Kyle_WG lightningmanic · Oct 08, 2015 at 05:52 PM 0
Share

Yeah. If one works of the same type then that has to be the issue! Hope you can reexport it. Try converting it to a different type too. Does the beetle render in scene view alright too? (if you just drag the object into the scene)

avatar image lightningmanic Kyle_WG · Oct 08, 2015 at 06:05 PM 1
Share

Definitely something wrong with my scarab_beetle.blend file. Not sure what, but I created a new file from scratch (just a sphere with a single-color texture map), and that's working well, even with the ScarabScript added to it. Looks like I'll just re-do my scarab beetle...wasn't sure I was happy with the first one anyway.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Checking if object intersects? 1 Answer

Why does this raycast keep hitting itself? 1 Answer

Instantiate at run time or previously then make active? 1 Answer

problems parenting a gameObject to another upon instantiating when same name exists 1 Answer

Instantiate as a child? 3 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