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;
}
}
}
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.
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

Follow this Question
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