How do I access the size of a sprite?

I’m not sure if it is possible to do that as I don’t use paper2d, but if it isn’t, it’s still possible to expose these functions to blueprints yourself, but it requires using C++ to make the custom node.
For example, here I’ve exposed UPaperSprite::GetSourceSize to blueprints, it’s pretty easy to add this to your project:

In ProjectName.Build.cs you will find the line


PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore" });

Add Paper2D to this so it looks as below:


PublicDependencyModuleNames.AddRange(new string] { "Core", "CoreUObject", "Engine", "InputCore", "Paper2D" });

This is so you can include Paper2D header files like PaperSprite.h, so you can make a blueprint node that takes one as an argument.

The header file for the node:

SpriteFunctions.h



#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "PaperSprite.h"
#include "SpriteFunctions.generated.h"


/**
 * 
 */
UCLASS()
class PROJECTNAME_API USpriteFunctions : public UBlueprintFunctionLibrary //Your project name in uppercase followed by "_API"
{
	GENERATED_BODY()

public:

	UFUNCTION(BlueprintPure, meta = (DisplayName = "Get Source Size", Keywords = "Source Texture Sprite"), Category = Custom) //Here you can change the keywords, name and category
		static FVector2D GetSourceSize(UPaperSprite* sprite);
	
};

SpriteFunctions.cpp


#include "ProjectName.h" //Replace with your project name
#include "PaperSprite.h"
#include "SpriteFunctions.h"

FVector2D USpriteFunctions::GetSourceSize(UPaperSprite* sprite)
{
	return sprite->GetSourceSize();
	
}

As you can see it’s pretty simple to set up, and you can easily add more functions to this function library so you can access them in blueprints.

The node in use:

For your second question, you could set them through the construction script with variables

2 Likes