Create sprite component

I thought of doing something similar to that:
.h:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Sprites)
		TSubobjectPtr<class UPaperSpriteComponent> BodySprite;

.cpp:

struct FConstructorStatics {
    	ConstructorHelpers::FObjectFinderOptional<UPaperSprite> BodyAsset;
    	FConstructorStatics() : BodyAsset(TEXT("/Game/Sprites/Character/Ship_Body.Ship_Body")) {}
} ConstructorStatics;
BodySprite = PCIP.CreateDefaultSubobject<UPaperSpriteCmponent>(this, TEXT("PlaneSprite0"));
// something like BodySprite->SetStaticMesh(ConstructorStatics1.PlaneMesh.Get());
RootComponent = BodySprite;

And whats the problem?

The problem is that i have no idea how to actually do this. The code above was just an idea. But I don’t know what variable to use for the sprite and how to initialize it so I could place it as an actual actor in my level.

Hello,

You can create a custom class, derived from Paper Sprite Component or Paper Sprite Actor from the editor just like any other class. However, please keep in mind that these classes come from Paper2D module, which may not be included to your project by default. To include it, please do the following:

  1. Go to Build.cs file of your project (YourProjectName\Source\ YourProjectName\ YourProjectName.Build.cs).

  2. In the file, find PublicDependencyModuleNames.AddRange command and add Paper2D to the list of included modules:

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

  3. Rebuild your project.

Now you can use the classes.

If you like to learn more about using sprites in Unreal Engine 4, please go here:

Hope this helped! Cheers!

That wasn’t quite what I was hoping for. Couldn’t I just attach the sprite like a mesh or an audio source to my class (derived from APawn)? I mean it works in blueprints where I can simply drag a sprite into the components view.