Hi there,
I’m struggling with GUI when extending editor by custom functions.
I’ve found a really weird behavior which I am convinced might be a bug:
I am creating in runtime dynamic TextBoxes and assigning names to them. To do so, I have a List of my own objects and one attribute of their class is unique id I am assigning as a suffix to each textbox. I am then checking GUI.GetNameOfFocusedControl() to do contextual information over selected TextBox.
I have an interface for adding and deleting textboxes with incremental addition of ID’s so basically I can see that
the name goes like: Edit0, Edit1, Edit2, Edit3 etc.
In this instance GUI.GetNameOfFocusedControl() works great
I also have a button for deleting any TextBox of my preference and here comes the problem:
If I add fields Edit0, Edit1 and Edit2 and later on I delete Edit1, the name is correctly generated as Edit0 and Edit2
However when Edit2 gets focus it is still identified by GetNameOfFocusedControl as Edit1 as if it was somehow cached!
Is it something for a bug report or am I missing some Invalidate method to refresh the cache?
Code excerpt:
// This shows correctly Edit0, Edit1, Edit2 and later on Edit0, Edit2 when I delete Edit1 from the collection
Debug.Log(name)
GUI.SetNextControlName(name);
_node.ModifyLineByKey(w, GUILayout.TextField (a.LineText, GUILayout.MaxWidth(400f)));
elsewhere I simply call:
// This is broken. While it originally shows Edit0, Edit1,Edit2 when I delete Edit1 Focus on Edit2 claims it's Edit1
Debug.Log(GUI.GetNameOfFocusedControl());
Thanks in advance!
Jan