How to get dimensions of a Texture 2DDynamic?

I’m downloading images from an url with the download image node. This gives me a Texture 2DDynamic which I have been able to successfully display on a widget. The images may be of different size and I would therefore like to be able to get the dimension (X and Y size) of the image to be able to resize the canvas panel slot where my image component resides in the widget. So I’m looking for something similar to the get size x and get size y which works for a Texture2D but not for a Texture 2DDynamic.

1 Like

I have the same issue and I cannot find a solution.

If I cannot get the dimensions, could I at least get the aspect ratio of the downloaded image?

1 Like

Hello asjobom and Vaidas,

the Texture 2D Dynamic stores it’s size in two public variables, namely SizeX and SizeY. You could write a simple Blueprint Function Library to expose them to Blueprint.

For example:

This goes inside the Blueprint Function Libary header file:

UFUNCTION(BlueprintCallable)
static int32 GetTexture2DDynamicWidth(UTexture2DDynamic* InTexture2DDynamicReference);

Important to note, you’ll need this include:

#include "Engine/Texture2DDynamic.h"

And this goes into the .cpp file:

int32 UMyBlueprintFunctionLibrary::GetTexture2DDynamicWidth(UTexture2DDynamic* InTexture2DDynamicReference)
{
	if (!InTexture2DDynamicReference)
	{
		return -1;
	}

	return InTexture2DDynamicReference->SizeX;
}

And the same goes for the height (or SizeY) you can make a second function or combine them it’s up to you.

Hope that helps. Just let me know if you need further assistance.

Regards,

Vecherka.

5 Likes

This solved hours of headaches, thank you so much!

Not sure why SizeX and SizeY aren’t exposable to Blueprints by default but they really should be!

2 Likes

SizeX and SizeY should be exposed to blueprint. @epic

its included in the Volumetrics plugin which goes with the engine.

2 Likes