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 ScottUnityNoob · Aug 25, 2017 at 01:56 AM · canvaseventsystemactivefirstselected

First Selected GameObject Help

Hello, I'm trying to do something very simple but unfortunately can't get it to work!

I have two Canvas', one for my "pause menu", another for a "quick selection wheel". If I drag a GameObject into the "First Selected" slot in the Event System Component, it works fine when it's parent Canvas is active. But when the other Canvas is active, I want to switch the "First Selected GameObject" to a button in that Canvas.

Using this script I can see that the "First Selected" in the event system component changes as expected, but it still doesn't let me select anything in the second canvas. (only the default first selected)

I've tried using SetSelectedGameObject() also to no avail.

Any help is greatly appreciated, Thanks!

public class FirstSelectedScript : MonoBehaviour {

 public GameObject canvasPause; 
 public GameObject canvasSelectionWheel; 

 public GameObject pauseButton1;
 public GameObject selwheelButton1;


 void Update () 
 {
     if(canvasPause.activeInHierarchy == true) 
     {
         print("Active Pause");
         EventSystem.current.GetComponent<EventSystem>().firstSelectedGameObject = pauseButton1;
     }
         
     if(canvasSelectionWheel.activeInHierarchy == true) 
     {
         print("Active Quick Selection Wheel");    
         EventSystem.current.GetComponent<EventSystem>().firstSelectedGameObject = selwheelButton1;
     }
 }

}

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 $$anonymous$$ · Aug 05, 2020 at 10:17 AM

Firstly Why use two canvases when you can group both menus to two different empty game objects and disable and enable the game objects? Try that. Unity does not work well with two canvases in one scene.

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 Koksny · Aug 11, 2020 at 03:52 AM 0
Share

This is not true, and this person has no clue what they talk about. In fact you should be using multiple canvases, to not redraw every UI element on changing any canvas element.

https://unity3d.com/how-to/unity-ui-optimization-tips

$$anonymous$$any users build their entire game’s UI in one single canvas with thousands of elements. So, when they change one element, they can experience a CPU spike costing multiple milliseconds (to hear more about why rebuilding is expensive, go to the 24:55 mark in Ian’s talk).

Solution: Divide up your canvases.

Each canvas is an island that isolates the elements on it from those of on other canvases. So, slicing up your canvases in the main tool available for resolving batching problems with Unity UI.

"Unity does not work well with two canvases in one scene. " Unity works better with multiple canvases. $$anonymous$$aybe don't answer if you have no clue about question.

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

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

Related Questions

If I disable/enable my canvas (pause game menu), controller navigation in the canvas stops to work? 1 Answer

Unity UI Events not working for Canvas objects 1 Answer

EventSystem raycasting on World Canvas gameobject always returning worldPosition of zero 2 Answers

OnPointerEnter blocked by something 2 Answers

How to render an image always on top? Already tried some solutions 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