C++ Sprite not loading

Hello World

I am trying to load a Sprite from the editor with 2 methods, cast and FindObject

Here are my codes:

Nothing in the viewport

you guys for your help :slight_smile:

Salut MasBASS,

I think there is a little bit of a misunderstanding regarding class inheritance. Your ‘ACCPSpawner’ class inherits from ‘APaperSpriteActor’ which main purpose is to provide a ‘UPaperSpriteComponent’. So you don’t need to add another ‘UPaperSpriteComponent’ in ‘ACCPSpawner’ class.

Now, to initialize the sprite of the Paper Sprite component stored inside ‘APaperSpriteActor’ class from your own class, do as follows :

MyPaperSpriteActor.h (which is ‘ACCPSpawner’ class in your project)

UCLASS()
class MYPROJECTCPP_API AMyPaperSpriteActor : public APaperSpriteActor
{
	GENERATED_BODY()
	
	// Sets default values for this actor's properties
	AMyPaperSpriteActor(const FObjectInitializer& ObjectInitializer);
};

MyPaperSpriteActor.cpp

AMyPaperSpriteActor::AMyPaperSpriteActor(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/AH_Issues/C++SpriteNotLoading/PaperSprite1.PaperSprite1'"));
	if (SpriteAssetObj.Succeeded())
	{
		GetRenderComponent()->SetSprite(SpriteAssetObj.Object);
	}
}

P.S. Please, next time post your c++ code as text, not as images.

Hope it helps!

Cheers.

Hello Elou44,

you a lot ! You’re the best !

It work really fine ! I’m new in c++ so there are some things that I don’t understand so I make some mistakes !

you again you really helped me, you for your time.

Sorry for the images, next time I will put the code in text :wink:

No problem, glad it works now!
As they say, the best way to learn is by doing mistakes :wink:

You’re right :wink: