How can I create an Image object from a texture2d? Or vice versa.

Hello, I am quite stuck on what I’d expect to be quite a simple issue.

When I spawn a buff object from class (in this case “Debuff Burn”) It takes an Image object that it then uses to display the image.

image

However my texture files are “Texture2d”

image

So how can I get the tab in my first picture filled in with the textures from the second picture?

Can I perhaps convert the textures to images in some way? Something like this?
image

I am also interested in knowing the vice versa because I could just change the debuff to take a texture, fixing the initial issue, but that means having to get the texture2d from an image object down the line, which I couldnt figure out either…


Tried to fix it like this: Letting my class take a texture (instead of an image object) and then constructing an image object and setting its brush before then sending it to my “add buff to slot” function

This doesn’t seem to work either as it’s still just using a white image (which im assuming is just what it defaults to)
image
Left (white box): The icon that becomes visible from running with construct image (or if i don’t select any texture at all)
Right (Arrows): The default icons when they are set correctly

Is there problems in my add buff to slot function maybe?

Ty in advance. Somehow I couldn’t really find anything similar, so I assume I’m just missing something ^^

Yes, (at least in the Widget Designer) white is the default when no Brush is set. So I also assume that the texture size gets properly set by Set Brush from Texture.

I have no ready solution, but for debugging,

  • maybe you could try to check if the input image from Add Buff to Slot is loaded (with the Is Loaded node)?
  • And/or try to Async Load Asset the image before sending it to the Make SlateBrush?

Appreciate the response

I was just about to hit the bed, Ill try your debugging suggestion in the morning and report back

ik such a weird issue i feel like ^^


Testing if texture is valid:
image

Testing if image is valid:
same as above just dragging buff img instead of texture.

Testing if image is valid inside add buff function:

All was valid, but it does make sense, since it just creates the image object with the white brush, it seems like the passed image does not have the updated brush from “set brush from texture”

Try with this one:

You can then just select a Texture2d asset from your calling event/spawn.


I applied it to my current system but with no luck still just a white image.

I found the solution going vice versa. Casting to texture2d.

I had tried this earlier without getting the brush from buff icon and then breaking that. But both objects seem to be the same to me, maybe someone can explain the difference in these pics =p

image

ahh i didnt notice your function Add buff to slot had Texture2d as input.

You can try to switch it to an Image/Widget Object Reference.

The param input in the slate Image is of type Object so it can accept anything (like texture 2d, material etc…)

That’s what I meant by vice versa i changed that to take a texture ref, but that lead to other code down the line needing to go from image->texture as seen on latest pics.

The first time i casted i just did it straight and it gave an error, but after getting brush, breaking that and then casting it worked fine.

Weird, but very happy I figured it out =D

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.