x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

alt text

alt text

Nothing in the viewport

alt text

Thank you guys for your help :)

Product Version: UE 4.20
Tags:
more ▼

asked Mar 19 '19 at 09:20 PM in C++ Programming

avatar image

MasBASS
27 3 4 7

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Mar 20 '19 at 01:51 AM

avatar image

Elou44
179 3 9 7

avatar image MasBASS Mar 20 '19 at 02:28 AM

Hello Elou44,

Thank 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 !

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

Sorry for the images, next time I will put the code in text ;)

avatar image Elou44 Mar 20 '19 at 02:34 AM

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

avatar image MasBASS Mar 20 '19 at 02:45 AM

You're right ;)

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question