Unity Community


Results 1 to 9 of 9

  1. Location
    Brazil
    Posts
    1,503

    Unity 4 - GUI.FocusControl() Broken?!?

    Hmm... Looks like it is broken in this b7 build; Can someone confirm this?
    I went back on every scene done to check if it is all ok and I noticed there are weird bugs in this remade OnGUI() interface.
    The main thing I see is the focus of controls seems bound to the mouse now, FocusControl() does nothing... Is it just me?

    It totally ruined my menu controlled by joysticks/keyboards.

    Note: Tested on Mac only. Not working.
    Last edited by BrUnO XaVIeR; 08-28-2012 at 04:49 AM.


  2. Posts
    60
    +1 but only full screen


  3. Posts
    23
    I'm seeing this in Unity 3.5.6f4 as well. As soon as fullscreen is activated, GUI.FocusControl() seems to have no effect.


  4. Posts
    101
    I think I also encountered this issue.

    I didn't raise any bugs since I've put the blame on my lack of programming skill and started doing something else, hoping that I would find the problem at a later date.

  5. Super Moderator
    Location
    Copenhagen, DK
    Posts
    784
    Just tried it on an old 3.5.2 and the latest internal 4.0 build and GUI.FocusControl is working.

    If this is not the case for you please submit a bug with a repro project.


  6. Location
    Brazil
    Posts
    1,503
    I am using Unity 4b7.
    SetFocus is not working here whatsoever; Not on editor, nor built.
    Bug is happening everywhere: editor, flash player, webplayer, standalone, fullscreen, windowed, etc.
    I guess this bug was introduced by the re-write of Unity GUI. Controls are focused by mouse only.

    Bug Report:
    Case 493113

    Sample code, this is working just fine in Unity 3.5 for me, but I can't make it work on Unity 4b7:
    Code:  
    1. using UnityEngine;
    2.  
    3. public class MainMenu : MonoBehaviour {
    4.     enum STATES{Main,Start,Load,Options}; STATES STATE = STATES.Main;
    5.     //
    6.     public GUIStyle BeginStyle;
    7.     public GUIStyle LoadStyle;
    8.     public GUIStyle OptionsStyle;
    9.     public GUIStyle QuitStyle;
    10.     //
    11.     private int FocusID = 0;
    12.     private float FocusTimer;
    13.     private bool FocusChanged;
    14.     //
    15.     //
    16.     void Start() {
    17.         Debug.Log("Using WASD keys as Vertical | Horizontal Axis.");
    18.     }
    19.     //
    20.     void OnGUI() {
    21.         FocusChanged=true;
    22.         //
    23.         if (STATE == STATES.Main) {
    24.             GUI.SetNextControlName("0");
    25.             if (GUI.Button(new Rect(50,Screen.height-(BeginStyle.fixedHeight*4),BeginStyle.fixedWidth,BeginStyle.fixedHeight),"",BeginStyle)) {
    26.                 STATE = STATES.Start;
    27.             }
    28.             //
    29.             GUI.SetNextControlName("1");
    30.             if (GUI.Button(new Rect(265,Screen.height-(LoadStyle.fixedHeight*2.85f),LoadStyle.fixedWidth,LoadStyle.fixedHeight),"",LoadStyle)) {
    31.                 //STATE = STATES.Load;
    32.             }
    33.             //
    34.             GUI.SetNextControlName("2");
    35.             if (GUI.Button(new Rect(525,Screen.height-(OptionsStyle.fixedHeight*2.1f),OptionsStyle.fixedWidth,OptionsStyle.fixedHeight),"",OptionsStyle)) {
    36.                 //STATE = STATES.Options;
    37.             }
    38.             //
    39.             GUI.SetNextControlName("3");
    40.             if (GUI.Button(new Rect(Screen.width-(QuitStyle.fixedWidth+10),Screen.height-(QuitStyle.fixedHeight+5),QuitStyle.fixedWidth,QuitStyle.fixedHeight),"",QuitStyle)) {
    41.                 Application.Quit();
    42.             }
    43.             //
    44.             FocusID = ManageFocus(FocusID,3);
    45.             if (Input.GetButtonDown("Jump")) {
    46.                 if (FocusID < 0) {return;}
    47.                 if (FocusID == 0) {Debug.Log("Another Menu Window.");}//STATE = STATES.Start;}
    48.                 if (FocusID == 1) {Debug.Log("Another Menu Window.");}//STATE = STATES.Load;}
    49.                 if (FocusID == 2) {Debug.Log("Another Menu Window.");}//STATE = STATES.Options;}
    50.                 if (FocusID == 3) {Application.Quit();}
    51.             }
    52.         } else {FocusID = -1;}
    53.         //
    54.             //...
    55.         //
    56.         if (STATE == STATES.Start) {
    57.             Application.LoadLevel("Menu");
    58.         }
    59.     }
    60.     //
    61.     // This is working on Unity 3.5, but 'GUI.FocusControl()' in Unity 4 is doing nothing; Or is 'GUI.SetNextControlName()' that is not working??
    62.     int ManageFocus(int ID, int Lenght) {
    63.         GUI.FocusControl(ID.ToString());
    64.         if (FocusChanged && Time.timeSinceLevelLoad > FocusTimer+0.35f) {FocusChanged=false; FocusTimer=Time.timeSinceLevelLoad;}
    65.         if ((Input.GetAxis("Vertical") < 0 || Input.GetAxis("Horizontal") > 0) && !FocusChanged) {FocusChanged=true; if (ID < Lenght) {ID++;}   Debug.Log("Focus:("+ID+") | Why don't this work in Unity 4?? The button used to be focused on Unity 3...");} else
    66.         if ((Input.GetAxis("Vertical") > 0 || Input.GetAxis("Horizontal") < 0) && !FocusChanged) {FocusChanged=true; if (ID > 0) {ID--;}        Debug.Log("Focus:("+ID+") | Why don't this work in Unity 4?? The button used to be focused on Unity 3...");}
    67.         if (ID < 0) {ID = -1;} if (ID > Lenght) {ID = Lenght;} return ID;
    68.     }
    69.     //
    70.     // Used by other scripts:
    71.     public void SetState(string ID) {
    72.         FocusID = -1;
    73.         if (ID == "Main") {STATE = STATES.Main;}
    74.         if (ID == "Start") {STATE = STATES.Start;}
    75.         if (ID == "Load") {STATE = STATES.Load;}
    76.         if (ID == "Options") {STATE = STATES.Options;}
    77.     }
    78. }
    Last edited by BrUnO XaVIeR; 10-11-2012 at 05:10 AM.


  7. Posts
    101
    I sent a bug (Case 49348. I hope it gets fixed someday since this is the only way to control the GUI with a gamepad or keyboard.

    I can't really post all my code here since there are multiple dependencies and that would be a mess. However, here is the FocusControl part that doesn't work. I receive all the logs and everything follows a simple logic that doesn't fail on runtime.

    Code:  
    1. for(var i = 0; i < dOptLength ; i++) {
    2.        
    3.             var iS = i.ToString();
    4.             GUI.SetNextControlName ("DialogueChoice" + iS);
    5.             Debug.Log("DialogueChoice" + iS); // I RECEIVE THIS LOG.
    6.             if (GUI.Button(Rect (dOptRectLocX, dOptRectLocYN, dOptRectScaleX, dOptRectScaleY), dOpt[i], dialogueChoicesStyle)) {
    7.                 NextDialogue(i);
    8.             }
    9.             dOptRectLocYN = dOptRectLocYN + dOptRectScaleY/1.4;
    10.         }
    11.        
    12.          if(Input.GetKeyDown("u")) {
    13.          
    14.          GUI.FocusControl ("DialogueChoice1");
    15.          Debug.Log("Done"); // I RECEIVE THIS LOG.
    16.          
    17.         }
    Last edited by alexandre.fiset; 10-10-2012 at 09:58 AM.


  8. Location
    Brazil
    Posts
    1,503
    I've got an email from Unity stating that the issue has been fixed and the fix will be available in a future beta; Let's wait


  9. Location
    Brazil
    Posts
    1,503
    Fix not available on b11... Pity
    Btw, I luv new icons. Tons of nice icons on b11.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •