Hello,
I have created a pawn in C++ which contains a custom component (based on USceneComponent). This component contains a UPaperSpriteComponent. I then create a blueprint based on that pawn and set a sprite for the component, then modify some other attributes. When I compile the blueprint, the sprite disappears. I have created a new clean project to demonstrate the problem.
Here is a video of it in action:
Here is the code I have:
MySceneComponent.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Components/SceneComponent.h"
#include "PaperSpriteComponent.h"
#include "MySceneComponent.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class MYPROJECT_API UMySceneComponent : public USceneComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UMySceneComponent();
// Called when the game starts
virtual void BeginPlay() override;
// Called every frame
virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
UPaperSpriteComponent* MySprite;
};
MySceneComponent.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject.h"
#include "MySceneComponent.h"
// Sets default values for this component's properties
UMySceneComponent::UMySceneComponent()
{
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
// off to improve performance if you don't need them.
bWantsBeginPlay = true;
PrimaryComponentTick.bCanEverTick = true;
// ...
MySprite = CreateDefaultSubobject<UPaperSpriteComponent>(TEXT("MySprite"));
MySprite->SetupAttachment(this);
}
// Called when the game starts
void UMySceneComponent::BeginPlay()
{
Super::BeginPlay();
// ...
}
// Called every frame
void UMySceneComponent::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
// ...
}
MyPawn.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Pawn.h"
#include "MyPawn.generated.h"
UCLASS()
class MYPROJECT_API AMyPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AMyPawn();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
USceneComponent* RootSceneComponent;
UPROPERTY(EditAnywhere, BlueprintReadOnly)
class UMySceneComponent* MyComponent;
};
MyPawn.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyProject.h"
#include "MyPawn.h"
#include "MySceneComponent.h"
// Sets default values
AMyPawn::AMyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
RootSceneComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
RootComponent = RootSceneComponent;
MyComponent = CreateDefaultSubobject<UMySceneComponent>(TEXT("MyComponent"));
MyComponent->SetupAttachment(RootComponent);
}
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyPawn::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
}
As a side question, what are the appropriate attributes to set in the UPROPERTY macro when declaring components? Thank you for your support.