Download

How to access sprites from c++

I have no idea how to get sprites from the editor in C++.
For example:

UPaperSprite* Sprite = ?

Where ‘?’ would be the sprite that I am wanting to get from the editor.

I figured it out, for anyone interested:

UPaperSprite* Sprite = Cast<UPaperSprite>(StaticLoadObject(UPaperSprite::StaticClass(), NULL, TEXT(“INSERTPATH”)));

To access the path of an asset, simply right click and choose ‘Copy Reference’.

Could you tell me how to connect the sprite to an actor that i spawned in, I can’t seem to find any good results when searching.

Figured it out, if you spawn in a custom actor that you made you have to set a UPaperSpriteComponent in the .h file.
ex.
UPROPRETY()
class UPaperSpriteComponent* Sprite Component,

then in the .cpp file in the constructor you fetch the sprite you want with

after that you just do
SpriteComponent = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT(“Sprite”));
SpriteComponent->SetupAttachement(RootComponent);
(if you want it to be your root component)
SpriteComponent->SetSprite(Sprite);