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
1
Question by turboPotato · Feb 18, 2017 at 06:44 PM · errorerror messageeventsystemerror-handling

Event System SetSelectedGameObject Error, but code still runs fine.

I'm using the following line of code to change the button selected by the event system when using a game pad:

EventSystem.current.SetSelectedGameObject(level_1);

However I'm getting the following error when it is called:

Attempting to select level_1 (UnityEngine.GameObject)while already selecting an object

The thing is the code still runs, and the button can't be selected by a game pad without it, but it still throws up the error.

Is this something I should be worried about? If not, can I just suppress the error and move on?

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
3

Answer by Jeremy2300 · Apr 05, 2017 at 12:33 AM

Just came across this and since no one has answered I thought I'd give my solution.

The SetSelectedGameObject function has a lock in place so it will select the first item sent to it in case of a conflict.

 public void SetSelectedGameObject(GameObject selected, BaseEventData pointer)
         {
             if (m_SelectionGuard)
             {
                 Debug.LogError("Attempting to select " + selected +  "while already selecting an object.");
                 return;
             }
 
             m_SelectionGuard = true;
             if (selected == m_CurrentSelected)
             {
                 m_SelectionGuard = false;
                 return;
             }
 
             // Debug.Log("Selection: new (" + selected + ") old (" + m_CurrentSelected + ")");
             ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.deselectHandler);
             m_LastSelected = m_CurrentSelected;
             m_CurrentSelected = selected;
             ExecuteEvents.Execute(m_CurrentSelected, pointer, ExecuteEvents.selectHandler);
             m_SelectionGuard = false;
         }

You can use:

 if( UnityEngine.EventSystems.EventSystem.current.alreadySelecting == true ){}

To check if that lock is activated and do with it what you like.

The biggest concern I have about the lock is if the item the does get selected, isn't what you want your final selection to be (this can be problematic when working with Gamepad navigation), so I usually give my assignments a priority and write a separate function that in turn calls SetSelectedGameObject().

Comment
Add comment · Show 1 · 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 JimmyCushnie · Apr 11, 2020 at 06:57 AM 0
Share

Thank you very much!

avatar image
0

Answer by gaterooze · Aug 07, 2020 at 08:10 PM

That error seems to throw when you select two buttons during the same frame (in my case I was using OnSelect() to push an onward button selection). If you delay the second selection until the end of the frame, the error goes away.

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

112 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

Related Questions

[Still need help]Help with Error 1 Answer

Array of dictionaries: "Object reference not set to an instance of an object" 0 Answers

Errors on Script? 1 Answer

Unable to get VRTK 3.2.1 working in Unity 5.6,Unable to get VRTK 3.2.1 to run in Unity 5.6 0 Answers

Hundreds off errors n console upon starting Unity 2018.3.9f1 related to "has no meta file" 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