• 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 GrahamShawcross · Oct 25, 2016 at 02:15 PM · strange ioc

With GvrGaze gameObject.Find followed by SetActive(false) permanently disables object (in future runs)

T$$anonymous$$s is the first time that I have felt the need to ask a question, so I hope that it is not a stupid one. I am trying to implement a simple VR "Continue", "Exit" interaction where the Exit option is followed by "Thank You". I have separate 3D objects for the options and wish to turn the "Thank You" option off at the start.

Unfortunately the code works fine ONCE but then permanently disables the object for future use with the following error message.

Awake: No Thanks Game Object UnityEngine.Debug:Log(Object) GvrGaze:Awake() (at Assets/GoogleVR/Scripts/UI/GvrGaze.cs:108)

Modifications to GvrGaze.cs

 using UnityEngine;
 using System.Linq;
 
   private GameObject myContinue;
   private GameObject myExit;
   private GameObject myThanks;
 
  void Awake() {
     cam = GetComponent<Camera>();
     PointerObject = pointerObject;
     myContinue = GameObject.Find ("Continue");
     if (myContinue == null) {
     Debug.Log ("Awake: No Continue GameObject");
     }
     myExit = GameObject.Find ("Exit");
     if (myExit == null) {
     Debug.Log ("Awake: No Exit GameObject");
     }
     myThanks = GameObject.Find ("Thanks");
     if (myThanks == null) {
     Debug.Log ("Awake: No Thanks Game Object");           **108**
     } else {
     myThanks.SetActive (false);
     }
     // DO NOT DEACTIVATE HERE (OTHERWISE PERMANENT !)
   }

Trying to deactivate in OnEnable has the same result.

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 bellicapax · Oct 25, 2016 at 03:54 PM 0
Share

Hi! Your code is really difficult to read without the code formatting option on for that block of text. Can you edit your post and turn it on? You can select the text and press the button. It's this button: codeFormattingButton

avatar image GrahamShawcross bellicapax · Oct 25, 2016 at 08:21 PM 0
Share

Thanks for the formatting tip

avatar image hexagonius · Oct 25, 2016 at 04:06 PM 0
Share

The problem is, GameObject.FInd can't find GameObjects that are inactive. You could only call Find if myThanks is null, because when you found it once, there's no need to search for it again. Why not making the fields public and assign those in the inspector? Don't answer if they're instantiated ;)

avatar image GrahamShawcross hexagonius · Oct 25, 2016 at 08:31 PM 0
Share

The ThankYou object is set as active in the scene. The code then works once. The object returns to being active in the scene But on a second run the error message occurs, and the object returns as active in the scene. The error message then re-occurs on every subsequent run and there is nothing you can do with the scene to turn it on again, for instance setting it as inactive and then as active again. The only thing that works is to delete the object and recreate it., when it will then work just once.

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

My Build Platform won't change. 0 Answers

Help with managing your character with the camera 0 Answers

How would I make a character select screen? 0 Answers

Need help with script 1 Answer

How to include js libraries ,.css 0 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