Accessing sprite data from APaperSpriteActor

Hi!

I’ve been trying to create some example 2D collectable items in my game and thus I’ve needed to have those 2D items as Actors (as I need to place them in world). I’ve created a USceneComponent object as RootComponent and now I want to attach a visual as UPaperFlipbook to the RootComponent. However, I can’ t find a way to do it - there are no functions to access any sprite data in APaperSpriteActor. Am I missing something?

PositionHolder = CreateDefaultSubobject<USceneComponent>(TEXT("PositionHolder"));
RootComponent = PositionHolder;
AppearanceSprite = CreateDefaultSubobject<UPaperFlipbook>(TEXT("AppearanceSprite"));
// GetSprite?? or how to now attach AppearanceSprite to RootComponent

Thanks!

AppearanceSprite->AttachParent = RootComponent; To attach the sprite to root component.

Then in your header file, make sure you have

UPROPERTY(EditDefaultsOnly, Category = "Sprite")
class UPaperFlipbook* AppearanceSprite;

To make sure, that you will be able to add the flipbook in editor for your actors. If you want to load flipbook object at runtime, then look into ConstructionHelpers, and how to load referenced objects in C++.

Sorry, but it says the following:
"Error class “UPaperFlipbook” has no member "AttachParent " as it’s UPaperFlipbook type (I know the name is quite misleading, but I was wondering I could use this type as some objects could have more than frames - for example shining and some would have one frame looping over and over again). The same error occurs with UPaperSprite type.

I’m not very familiar working with Paper2D, so if I’m doing it wrong, tell me :).
I don’ t know very well how it would affect performance.

I think you are looking for UPaperSpriteComponent… this needs to be attached to the RootComponent. And then set the sprite of your UPaperSpriteComponent to be the paper flipbook.

Hope that helps!

Thanks, this perfectly solved my problem. However, I just realized, that there’s a RenderComponent inherited from APaperSpriteActor already among the components in my class.
So, inheriting APaperSpriteActor should be used to rather create “static” (there’s no flipbook, but sprite) objects in game?

In addition, if you don’ t mind - what for I should use UPaperSprite or UPaperFlipbook?

Thanks again! If it seems the answer could be long, I could make a new post about it as I haven’ t found answer for those questions.