• 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 MatsLindestam · Oct 06, 2015 at 08:40 AM · guibuttonsinstances

Different Buttons, in the same scene, have the same InstanceID

Hi,

I have an issue where different Buttons have the same InstanceID.

In my scene (PlayerSettingsMenu) I have a Canvas containing PlayerPanes (Panel). In the scene there are four PlayerPanels (PlayerPanelOne, PlayerPanelTwo, PlayerPanelThree & PlayerPanelFour).

Here is the script (PlayerSettingsMenuManager) in charge of the Panels:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 using System.Collections.Generic;
 
 public class PlayerSettingsMenuManager : MonoBehaviour
 {
 
     private PlayerPanel playerPanelOne;
     private PlayerPanel playerPanelTwo;
     private PlayerPanel playerPanelThree;
     private PlayerPanel playerPanelFour;
 
     // 
     void Awake ()
     {}
 
     // Use this for initialization
     void Start()
     {
         initialize();
     }
 
     // Update is called once per frame
     void Update () { }
 
     /// <summary>
     /// Changes game scene. Uses scene indices.
     /// </summary>
     /// <param name="sceneIndex">Index of the scene to change to.</param>
     public void changeToScene(int sceneIndex)
     {
         Application.LoadLevel(sceneIndex);
     }
 
     /// <summary>
     /// Changes game scene. Uses scene name.
     /// </summary>
     /// <param name="sceneName">Name of the scene to change to.</param>
     public void changeToScene(string sceneName)
     {
         Application.LoadLevel(sceneName);
     }
 
     private void initialize()
     {
         playerPanelOne = new PlayerPanel(GameObject.Find("PlayerPanelOne"));
         if (null != playerPanelOne)
         {
             //playerPanelOne.SetActive(false);
             playerPanelOne.SetAsFirstSibling();
         }
 
         playerPanelTwo = new PlayerPanel(GameObject.Find("PlayerPanelTwo"));
         if (null != playerPanelTwo)
         {
             //playerPanelTwo.SetActive(false);
             playerPanelTwo.SetAsFirstSibling();
         }
 
         playerPanelThree = new PlayerPanel(GameObject.Find("PlayerPanelThree"));
         if (null != playerPanelThree)
         {
             //playerPanelThree.SetActive(false);
             playerPanelThree.SetAsFirstSibling();
         }
 
         playerPanelFour = new PlayerPanel(GameObject.Find("PlayerPanelFour"));
         if (null != playerPanelFour)
         {
             //playerPanelFour.SetActive(false);
             playerPanelFour.SetAsFirstSibling();
         }
     }
 }
 

Here is the PlayerPanel class:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 
 public class PlayerPanel {
 
     // Names of PlayerPanel GameObjects.
     public static readonly string PLAYERPANEL_GAMEPAD_BUTTON = "GamepadButton";
     public static readonly string PLAYERPANEL_KEYBOARD_BUTTON = "KeyboardButton";
 
     private GameObject panel;
     private GameObject gamepadButton;
     private GameObject keyboardButton;
 
     public PlayerPanel(GameObject gameObject)
     {
         this.panel = gameObject;
         Debug.Log("Panel Name: " + this.panel.name + ", Panel InstanceID: " + this.panel.transform.GetInstanceID());
 
         // Find PlayerPanel Buttons.
         keyboardButton = GameObject.Find(PLAYERPANEL_KEYBOARD_BUTTON);
         gamepadButton = GameObject.Find(PLAYERPANEL_GAMEPAD_BUTTON);
 
         this.reset();
     }
 
     /*******************
     * Properties
     ********************/
     public GameObject Panel
     {
         get { return panel; }
     }
 
     /*******************
     * Public Methods
     ********************/
     public void SetActive(bool value)
     {
         panel.SetActive(value);
     }
 
     public void SetAsFirstSibling()
     {
         panel.transform.SetAsFirstSibling();
     }
 
     public void SetAsLastSibling()
     {
         panel.transform.SetAsLastSibling();
     }
 
     public void reset()
     {
         if (null != gamepadButton)
         {
             Debug.Log("Gamepad GameObject Name: " + gamepadButton.name + ", Gamepad GameObject InstanceID: " + gamepadButton.transform.GetInstanceID());
 
             Button button = gamepadButton.GetComponent<Button>();
             Debug.Log("Gamepad Button Name: " + button.name + ", Gamepad Button InstanceID: " + button.transform.GetInstanceID());
 
             // Disabel PLAYERPANEL_GAMEPAD_BUTTON and set disable color.
             Text text = button.GetComponentInChildren<Text>();
             Debug.Log("Gamepad Button Text Name: " + text.name + ", Gamepad Button Text InstanceID: " + text.transform.GetInstanceID());
             text.color = GameColors.BUTTON_DISABLED_TEXT_COLOR;
             //gamepadButton.GetComponent<Button>().enabled = false;
             button.interactable = false;
         }
     }
 }    

In each Panel there is a GamepadButton. At the start of the scene all the GamepadButtons should be disabled. This is done in the PlayerPanel constructor which is calling the reset()-method.

Now my problem is that only one of the GamepadButtons gets disabled. Not the others (see picture).

alt text

I added some prints in the PlayerPanel-constructor and in the reset()-method. I print the name and InstanceID of each Panel, GamepadButton-GameObject, GamepadButton-Button & GamepadButton-text. Each of the four PlayerPanels had different InstanceID, but to my surprice each GamepadButton-GameObject, GamepadButton-Button & GamepadButton-text had the same InstanceID in each panel. That, to me, indicates that they all are the same instance/object. How can that be?

Here is the printout from the PlayerPanels:

 Panel Name: PlayerPanelOne, Panel InstanceID: 7648
 Gamepad GameObject Name: GamepadButton, Gamepad GameObject InstanceID: -2210
 Gamepad Button Name: GamepadButton, Gamepad Button InstanceID: -2210
 Gamepad Button Text Name: Text, Gamepad Button Text InstanceID: -2232
 
 Panel Name: PlayerPanelTwo, Panel InstanceID: 7652
 Gamepad GameObject Name: GamepadButton, Gamepad GameObject InstanceID: -2210
 Gamepad Button Name: GamepadButton, Gamepad Button InstanceID: -2210
 Gamepad Button Text Name: Text, Gamepad Button Text InstanceID: -2232
 
 Panel Name: PlayerPanelThree, Panel InstanceID: 7774
 Gamepad GameObject Name: GamepadButton, Gamepad GameObject InstanceID: -2210
 Gamepad Button Name: GamepadButton, Gamepad Button InstanceID: -2210
 Gamepad Button Text Name: Text, Gamepad Button Text InstanceID: -2232
 
 Panel Name: PlayerPanelFour, Panel InstanceID: 7622
 Gamepad GameObject Name: GamepadButton, Gamepad GameObject InstanceID: -2210
 Gamepad Button Name: GamepadButton, Gamepad Button InstanceID: -2210
 Gamepad Button Text Name: Text, Gamepad Button Text InstanceID: -2232
 

It puzzles me that the InstanceIDs are negative. Something is fishy here. :-)

panels-gamepadbuttons.png (8.1 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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Determining GUI button pressed 2 Answers

GUI Texture Changes Position Depending On Screen Resolution? 1 Answer

GUI.enabled ? 0 Answers

How will i develop the type of gui? 0 Answers

GUI buttons don't show up in seccond scene 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