EditorWindow.titleContent.image doesn't work properly

Hi guys,

I have another problem and am searching for ours.
I just want to create a new EditorWindow called “MyEditorWindow” with a title “MyEditorWindow” and an icon “MyEditorWindow.png”. I try it as following:

void OnEnable()
{
     titleContent = new GUIContent("MyEditorWindow",
                                   AssetDatabase.LoadAssetAtPath<Texture>("<path to image>/MyEditorWindow.png"),
                                   "This is a tooltip.");
}

The icon is marked as editor GUI image, but it does only appear, if i move the window. Can anyone help me?

Kind regards,

Winder

No icon while the window is docked:

2979581--221528--upload_2017-3-2_22-43-42.png

The image import settings:

While moving the window:

2979581--221531--upload_2017-3-2_22-48-5.png

2979581--221530--upload_2017-3-2_22-46-39.png

As soon as I posted this thread, I found the solution:

The title is too long and moves the icon to the left, outside of the title bar. But this leads me to another question: Is there a way to edit the length of the title bar, so that the icon AND a long title are displayed properly?

Sucks when no one replies…

If anyone else ends up here, the solution is to limit the number of characters your string outputs when declaring your guicontent:

myString.Substring(0, maxLength)
// or
"AStringThatIsTooLong".Substring(0, maxLength)

0 to maxLength being the range we want to output from the string.
If your string may be smaller than your maxLenght use this instead:

myString.Substring(0, myString.Length >= maxLength ? maxLength:myString.Length);