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 /
  • Help Room /
avatar image
0
Question by IVl1K3 · Aug 11, 2017 at 06:47 AM · editorinputdebughierarchy

activeInHierarchy code not being reflected correctly in Editor although debugging shows correct code

This will be a long post, I apologize for the length.

I'm running into a problem where the Editor doesn't seem to be reflecting the code properly. There's two important scripts interacting that I'll break down here:

My main game control script handles switching between the two main game states Orientation A and Orientation B. It switches back and forth on a button press depending on if the player's main character is active. If it is, it'll switch depending on the current state and if it isn't it'll reset back to the original state.

 public class GameControl : MonoBehaviour {
 
     public GameObject OrientationA;
     public GameObject OrientationB;
     public GameObject CombinedOrient;
     public GameObject player;     //the player's main character
     private GameObject player5;   //another character in the scene
     public GameObject respawnPoint;
     public bool switchPressed;
 
 public void Start () {
         OrientationA.SetActive(true);
         OrientationB.SetActive(false);
         CombinedOrient.SetActive(false);
         player5 = GameObject.FindWithTag("Player5");
         player.SetActive(true);
         player.transform.position = respawnPoint.transform.position;
         if (player5 != null)       //some scenes won't have this character in them
         {
             player5.SetActive(true);
         }
         switchPressed = false;
     }
     
     void Update () {
 
         if (Input.GetButtonDown("Fire3")) 
         {
             Debug.Log("Player is " + player.activeSelf);
             if (player.activeSelf == true)
             {
                 Debug.Log("Switching");
                 switchPressed = !switchPressed;
                 SwitchOrient();
             }
             else if (player.activeSelf == false)
             {
                 Debug.Log("Resetting");
                 Start();
             } 
         }
     }
 
     void SwitchOrient()
     {
         
         if (switchPressed == false)   //B to A
         {
             Debug.Log("Switching B to A");
             OrientationA.SetActive(true);
             Debug.Log("A is " + OrientationA.activeInHierarchy);
             OrientationB.SetActive(false);
             Debug.Log("B is " + OrientationB.activeInHierarchy);
             CombinedOrient.SetActive(false);
             Debug.Log("Combined is " + CombinedOrient.activeInHierarchy);
         }
         else if (switchPressed == true)     //A to B
         {
             Debug.Log("Switching A to B");
             OrientationB.SetActive(true);
             Debug.Log("B is " + OrientationB.activeInHierarchy);
             OrientationA.SetActive(false);
             Debug.Log("A is " + OrientationA.activeInHierarchy);
             CombinedOrient.SetActive(false);
             Debug.Log("Combined is " + CombinedOrient.activeInHierarchy);
         }
     }

All of the extra nonsense in there about "player5" and Combined Orient and such has to do with the second script. This is attached to another character in the scene and upon a button press it will "combine" Orientation A and B, which is really just activating the third state, CombinedOrient. Everything about this script works perfectly.

 public class PlayerCombine : MonoBehaviour {
 
     public bool combine;
     public float combinedTime = 5.0f;
     private float separate = 0;
     public GameObject GameController;
     private GameControl control;
     public GameObject MainPlayer;
 
     void Start () {
         control = GameController.GetComponent<GameControl>();
         combine = false;
     }
     
     void Update () {
 
         if (Input.GetButtonDown("Fire4") && combine == false)
         {
             combine = true;
             Debug.Log("Combining");
         }
 
         if (combine == true && control.OrientationA.activeSelf == true && MainPlayer.activeSelf == true)
         {
             control.OrientationA.SetActive(false);
             control.OrientationB.SetActive(false);
             control.CombinedOrient.SetActive(true);
         }
         else if (combine == false && control.CombinedOrient == true && MainPlayer.activeSelf == true)
         {
             control.OrientationA.SetActive(true);
             control.OrientationB.SetActive(false);
             control.CombinedOrient.SetActive(false);
         }
 
         if (combine == true)
         {
             separate += Time.deltaTime;
             if (separate >= combinedTime)
             {
                 combine = false;
                 separate = 0;
             }
         }
 
 
     }
 }


The problem that's arising is that when the main character is in a position in the scene where they will remain active after switching game states, the states do not switch...in the Editor. They do however switch in code which I can verify by having all of the Debug code in there. The states also switch if the player will deactivate after switching states. Essentially if the player is supposed to survive the switch, the code will run correctly but the Editor does not switch the states. If the player will die when switched, the code and Editor switch the states as planned.

Example: The game is in Orientation A and the player is in a safe spot where they'll survive when they switch. Player presses the button to switch from A to B. The code runs and this is the result:

alt text

The most annoying part is that when I remove Player5 from the scene, therefore eliminating the possibility of using the Combined game state, there are no problems with switching between A and B. So I'm not sure if it has something to do with how these two scripts are communicating with each other or if it's something to do with the Editor.

Hopefully all of this makes sense and isn't a big mess to try to understand. Any help on the matter is greatly appreciated, I've been trying to work this out for a week! D,x I'm hoping I'm just overthinking everything and someone will figure it out easily :D

puzzler-editorissue.jpg (76.2 kB)
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

Answer by IVl1K3 · Oct 12, 2017 at 03:43 PM

I'm still not able to figure this out and could really use any help that anyone has.

Is there anything I can add to make this easier to solve?

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

92 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

Related Questions

What can I do to get Unity to understand the Debug.Drawline command? 1 Answer

Keyboards Input not working 1 Answer

Change debug level in inspector 0 Answers

HideFlags.HideInHierarchy not updating hierarchy in Edit-mode 3 Answers

HideFlags and Prefabs 1 Answer


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