How to get texture 2d array size in blueprint?

I’m trying to get the array size of a texture 2d array object in blueprint. Searched on google and there seems to be no docs on this.

It seems that there is no blueprint accessible logic for accessing the size, but it does exist in C++ as int32 GetArraySize() const;

You can make this accessible to blueprints via a BlueprintFunctionLibrary like so:

	UFUNCTION(BlueprintCallable, BlueprintPure, Category="Texture2DArray", meta=(CompactNodeTitle="Length"))
	static UPARAM(DisplayName=" ") int32 GetTexture2DArrayLength(const UTexture2DArray* Texture2DArray)
	{
		return Texture2DArray->GetArraySize();
	}

or without the frills:

	UFUNCTION(BlueprintCallable)
	static int32 GetTexture2DArrayLength(const UTexture2DArray* Texture2DArray)
	{
		return Texture2DArray->GetArraySize();
	}

It doesn’t have to be in a blueprint function library, but it makes most sense to put it in one.


For those who don’t have C++ set up, below are instructions on how to quickly do that, no experience needed.

Follow this video guide, but when he says to select none when adding the C++ class, instead scroll down and add a blueprint function library.


Additionally, when he does “Advanced build actions → rebuild selected projects,” you can just press the play icon or hammer icon, whichever you can find in visual studio.
https://www.youtube.com/watch?v=tW1_rD0Geiw

Add in the code, and it should look something like this (YETANOTHERTESTING_API will be different for you)

@rokenrock Thanks for your reply. But I was not able to access these in blueprint. How to do it? And I would like to do this in texture2darray to reduce texture samples.

Bump. Looking to count those textures also.

My bad- I’ve rewritten the reply to properly answer the question. Let me know if there are any issues

1 Like


You can convert Texture to Texture2d and get the rows and columns. If you have access to the Texture and not only Texture2DArray.