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 Wesley21spelde · Nov 07, 2016 at 09:48 AM · gameobjectsetactivenot found

Reactivate GameObjects that are disabled not working??

Hey guys im trying to exit the turrent but my script can not find or activate my player and my off turrent

how can i fix this ??

 using UnityEngine;
 using System.Collections;
 
 public class ExitTurrent : MonoBehaviour
 {
     public GameObject Turrent;// the player turrent
     public GameObject Player; // the player
     public GameObject TurrentOff;// the scene turrent
     public bool inTurrent = true;
     EnterTurrent turrentscript;
     GameObject guiObj;
     AudioSource source;
     public AudioClip audio;
 
     // Use this for initialization
     void InTurrent()
     {
         inTurrent = true;
         Player = GameObject.Find("_SpartanPlayer");// Find Player
         Player.SetActive(false);
         Turrent.SetActive(true);
         TurrentOff.SetActive(false);
 
     }
     void Update ()
     {
         if (Input.GetKeyDown(KeyCode.E))
         {
             Player = GameObject.Find("_SpartanPlayer");// Find Player
             TurrentOff = GameObject.Find("UNSC Warthog MK1");
             SendMessage("GetOut");
             Debug.Log("Getout");
         }
     }
     // Update is called once per frame
     void GetOut()
     {
         {
             Player = GameObject.Find("_SpartanPlayer");// Find Player
             Player = GameObject.FindGameObjectWithTag("Player");// Find Player
             TurrentOff = GameObject.Find("UNSC Warthog MK1");// Find Player
             Player.SetActive(true);
             BroadcastMessage("Playertrue");
             Player.transform.parent = null;
             TurrentOff.transform.parent = null;
             Turrent.SetActive(false);
             TurrentOff.SetActive(true);
             turrentscript.enabled = false;
             inTurrent = false;
         }
 
     }
 }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · Nov 07, 2016 at 05:34 PM

GameObject.Find won't find disabled GameObjects. That means that if you don't have a reference to them, they are gone forever. What you can do is either keep the reference in a variable, make the disabled GameObject a child of another GameObject so you can find the parent and find the child´from that, or not disable the whole GameObject, but instead only those components neccessary, such as Renderers, Colliders, and scripts.

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 Cynikal · Nov 07, 2016 at 05:58 PM

Your code is already there. You're already setting the "player" variable.

Remove the "Player = GameObject.Find("_SpartanPlayer");// Find Player" from your Update & GetOut. You're already setting it in "GetIn". Since it's already set, then when you try to find a disabled game object, you're setting it back to null.

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

game object set active on trigger enter? 3 Answers

How to swap gameObjects on the press of a button? 1 Answer

activate GameObject dont work 1 Answer

Override SetActive on a GameObject? 1 Answer

gameObject.setActive(false) is disabling the wrong objects 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