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"

UE4 C++ UPaperSprite array ???

Hello peeps ! I'm trying to put some Sprites into an array in C++ like in my blueprint: alt text

.h file

         UPROPERTY()
         TArray <UPaperSprite*>  spriteArray;
 

And I have some errors like: error C2065: 'UPaperSprite'?: Undeclared identifier error C2059: syntax error?: '>'

Product Version: UE 4.20
Tags:
spritearray.png (484.8 kB)
more ▼

asked Apr 12 '19 at 04:01 AM in C++ Programming

avatar image

MasBASS
32 3 4 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

To use UPaperSprite in C++ you need to add the "Paper2D" module to your project.

To do that go to your Source\YOUR_PRPJECTNAME\YOUR_PRPJECTNAME.Build.cs file and add "Paper2D" to the dependency module names range.

In 4.21 it should look like this: PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "GameplayAbilities", "GameplayTags", "GameplayTasks", "AIModule", "Paper2D" });

more ▼

answered Apr 13 '19 at 06:46 AM

avatar image

Lardo Deepdelver
951 6 4 6

avatar image MasBASS Apr 13 '19 at 10:35 AM

Hello Lardo, thank you for your reply :D. I already do this, here is my code for more precision: .h file: // Fill out your copyright notice in the Description page of Project Settings.

 #pragma once
 
 #include "CoreMinimal.h"
 #include "PaperSpriteActor.h"
 #include "CPP_Trash.generated.h"
 
 /**
  * 
  */
 UCLASS()
 class FNJCPP_API ACPP_Trash : public APaperSpriteActor
 {
     GENERATED_BODY()
 
 public:
 
     ACPP_Trash(const FObjectInitializer& ObjectInitializer);
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BoxCollision)
     class UBoxComponent* BoxComponent;
 
     UFUNCTION()
     void CustomOnBeginMouseOver(UPrimitiveComponent* TouchedComponent);
     
     UPROPERTY()
     TArray<UPaperSprite*> spriteTab;
 
 protected:
     virtual void BeginPlay();
 
 };
 

.cpp file:

 // Fill out your copyright notice in the Description page of Project Settings.
 
 #include "CPP_Trash.h"
 #include "Components/BoxComponent.h"
 #include "Engine.h"
 #include "PaperSprite.h"
 #include "PaperSpriteComponent.h"
 #include "Runtime/CoreUObject/Public/UObject/ConstructorHelpers.h"
 
 ACPP_Trash::ACPP_Trash(const FObjectInitializer& ObjectInitializer)
 {
 
     ConstructorHelpers::FObjectFinder<UPaperSprite> SpriteAssetObj(TEXT("PaperSprite'/Game/Assets/Organic/T_Cheese_Sprite.T_Cheese_Sprite'"));
 
     if (SpriteAssetObj.Succeeded())
     {
         GetRenderComponent()->SetSprite(SpriteAssetObj.Object);
     }
 
     BoxComponent = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollision"));
     BoxComponent->AttachTo(RootComponent);
     BoxComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
 
 }
 
 void ACPP_Trash::BeginPlay()
 {
     // Call the base class  
     Super::BeginPlay();
 }

And the compiler doesn't like this:

      UPROPERTY()
      TArray<UPaperSprite*> spriteTab;

avatar image Lardo Deepdelver Apr 13 '19 at 12:57 PM

You need to either forward declare UPaperSprite or include the header for it

add class UPaperSprite; in the header

 #pragma once
 
 #include "CoreMinimal.h"
 #include "PaperSpriteActor.h"
 #include "CPP_Trash.generated.h"
 
 class UPaperSprite;
 
 /**
  *
  */
 UCLASS()
 class ACPP_Trash : public APaperSpriteActor
 {
     GENERATED_BODY()
 
 public:
 
     ACPP_Trash(const FObjectInitializer& ObjectInitializer);
 
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = BoxCollision)
     class UBoxComponent* BoxComponent;
 
     UFUNCTION()
     void CustomOnBeginMouseOver(UPrimitiveComponent* TouchedComponent);
 
     UPROPERTY()
     TArray<UPaperSprite*> spriteTab;
 
 protected:
     virtual void BeginPlay();
 
 };

On another note i had to rexecute "Generate Visual Studio Project Files" to get the Paper2D module into the code.

avatar image MasBASS Apr 13 '19 at 10:16 PM

Thank you sir for your help, I already do the "Generate Visual Studio Project Files", but I didn't put the class UPaperSprite in the header, now it works, thank you again :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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