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 imaginethepoet · Feb 28, 2018 at 11:52 PM · gameobjecttimergameobject.find

GameObject Wont' Set Active,Set active doesn't work trying to do something simple.

I've been working on this for quite a long time. I'm familiar with unity but working on my C# skills. These seem like they should be simple actions to do, but after days and nights looking at this script, it won't work.

All I'm trying to do is display a scene with an active object, then show it for 40 seconds, hide it, and show a new object.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LoadWeatherShelf : MonoBehaviour {
 
     //Todo
     //Hide Object 1 after 40 seconds
     //Display A new object
 
 
     // Use this for initialization
     void Start () {
 
         Invoke("NextObject", 40);
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void NextObject ()
     {
         GameObject.Find("PrimarySceneContent").SetActive(true);
 
 
     }
 

Any help is appreciated!

,I spent a lot of time working on this nights and days and hours and still can't get this to work right. It's some dumb mistake I'm sure.

I'm simply trying to deactivate one object (not destroy), after a set duration 40seconds, and then turn on another object that is de-activated. I've tried so many varieties. Nothing works.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class LoadShelf : MonoBehaviour {
 
     //Todo
     //Hide Object 1 after 40 seconds
     //Display A new object
 
 
     // Use this for initialization
     void Start () {
 
         Invoke("NextObject", 40);
         
     }
     
     // Update is called once per frame
     void Update () {
         
     }
 
     void NextObject ()
     {
         GameObject.Find("PrimarySceneContent").SetActive(true);
 
 
     }
 
Comment
Add comment · Show 1
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 hrishihawk · Mar 01, 2018 at 07:06 AM 0
Share

Do you get any error message ?

1 Reply

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

Answer by hrishihawk · Mar 01, 2018 at 07:28 AM

The problem is you're trying to find an object which is already inactive in the scene. So you should be getting a NullReferenceException after 40 seconds. So what you want to do is to have a reference of the object you want to activate in the script already instead of trying to find it using GameOject.Find. You can modify your script as follows :

 public GameObject objectToActivate ;

And in your NextObject method :

      void NextObject ()
      {
          objectToActivate.SetActive(true);
      }
Comment
Add comment · Show 2 · 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 Greg_lrgg · Mar 01, 2018 at 07:41 AM 0
Share

Hi @imaginethepoet. As @hrishihawk said, when you deactivate an object it does not appear on the Scene neither on the hierarchy. So you have to preemptively take an instance of it which will still "exists" whatever you do with the object, albeit not destroying it. You could watch the activate/deactivate tuto video from Unity, it is well explained how deactivation actually works.

avatar image imaginethepoet · Mar 01, 2018 at 01:56 PM 0
Share

Thank you for your response!

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

113 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Find one inactive player (gameobject) 2 Answers

How to access a game object from a different scene? 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Find an inactive game object 12 Answers

Delay "Destroy(gameObject)" 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