Displaying Images In Editor Window

Hello, I decided to learn how to create editor windows. Most things are going fine, but I am having a hard time getting an image to show up. For a simple test my .uss file just specifies a width and height for the image (100,100). When using the UI Element debugger i can see it is there, but I can never actually see the image I am trying to set.

The c# code I am using to set its image, and add it to my root visual element is

Image image = new Image();
image.image = Resources.Load("TestTexture.png") as Texture2D;
root.Add(image);

Can anyone tell me what I am doing wrong / the correct way to display an image. I looked at the UI Samples but didn’t see anything, and also checked out the UI Element examples github project but didn’t see anything about Images, unless I overlooked it.

What I want to achieve is a little tool that I can use to help me create scriptable objects for my game, where i specify text data with text fields, a sprite via an object field, I want to have a nice visual of the sprite when i set it and that is what I will eventually use the image for.

When using Resources.Load(), you should not add the file extension in the path. So just look for “TestTexture”. Always good to make sure the result from Resources.Load() is not null. :slight_smile:

Also, the Image element is maybe overkill for what you need. You can just assign a background image to any element (but use just the plain VisualElement), by setting the style:myElement.style.backgroundImage = Resources.Load(...);

Hello kevin

I would advice that many editor are available with thousands of features. It’s better to use a editor window that is already designed with good objects. Scriptable Objects are fantastic data storage containers. They don’t wish to be linked to any Game Objects in the scene. They can be kept as belongings in our project.

Thanks!

1 Like