MasBASS
(MasBASS)
April 12, 2019, 4:01am
1
Hello peeps !
I’m trying to put some Sprites into an array in C++ like in my blueprint:
.h file
UPROPERTY()
TArray <UPaperSprite*> spriteArray;
And I have some errors like:
error C2065: ‘UPaperSprite’?: Undeclared identifier
error C2059: syntax error?: ‘>’
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 ” });
MasBASS
(MasBASS)
April 13, 2019, 10:35am
3
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;
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.
MasBASS
(MasBASS)
April 13, 2019, 10:16pm
5
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