How to Create and Attach a Paper Sprite Component?

I am trying to create a paper sprite component like this:

.h

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Sprites")
class UPaperSpriteComponent* PrimarySprite;

.cpp

PrimarySprite = ObjectInitializer.CreateDefaultSubobject<UPaperSpriteComponent>(this, TEXT("PrimarySprite"));

PrimarySprite->AttachTo(RootComponent);

However, this does not compile. I get the following errors:

Error 1: use of undefined type ‘UPaperSpriteComponent’

Error 2: ‘StaticClass’: identifier not found

Error 3: ‘static_cast’ : cannot convert from ‘UObject *’ to ‘UPaperSpriteComponent *’

What is the proper way to create and attach a paper sprite component to a root component? This is the same way I have done other objects in the past (static meshes, spheres, lights, etc.). What makes the paper sprite component different?

Well, I’m dumb. This code works, assuming you have the PaperSpriteComponent.h file included…

1 Like