So, I’m adding a UPaperFlipbookComponent to a SceneComponent.
The goal here is that the SceneComponent will be a changeable limb on a character. These limbs will have their own logic, and do a variety of things, so I wanted to just keep the Flipbook as a part of the Component.
I’m adding the SceneComponent to a Character like so:
AEVOSpriteCharacter::AEVOSpriteCharacter(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer.DoNotCreateDefaultSubobject(ACharacter::MeshComponentName))
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Try to create the sprite component
Body = ObjectInitializer.CreateDefaultSubobject<UEVOBodyPartsComponent>(this, AEVOSpriteCharacter::BodyComponentName);
if (Body)
{
Body->SetupAttachment(GetCapsuleComponent());
Body->SetMobility(EComponentMobility::Movable);
}
Head = ObjectInitializer.CreateDefaultSubobject<UEVOBodyPartsComponent>(this, AEVOSpriteCharacter::HeadComponentName);
if (Head)
{
Head->SetupAttachment(GetCapsuleComponent());
Head->SetMobility(EComponentMobility::Movable);
}
Legs = ObjectInitializer.CreateDefaultSubobject<UEVOBodyPartsComponent>(this, AEVOSpriteCharacter::LegsComponentName);
if (Legs)
{
Legs->SetupAttachment(GetCapsuleComponent());
Legs->SetMobility(EComponentMobility::Movable);
}
Arms = ObjectInitializer.CreateDefaultSubobject<UEVOBodyPartsComponent>(this, AEVOSpriteCharacter::ArmsComponentName);
if (Arms)
{
Arms->SetupAttachment(GetCapsuleComponent());
Arms->SetMobility(EComponentMobility::Movable);
}
}
And the BodyPartsComponent.h holds a flipbookcomponent:
UPROPERTY(Category = "BodyPartInfo", VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
class UPaperFlipbookComponent* BodyPart;
And initializes its FlipbookComponent like this:
// Sets default values for this component's properties
UEVOBodyPartsComponent::UEVOBodyPartsComponent(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
// 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;
ComponentName = TEXT("BodyPart00");
BodyPart = ObjectInitializer.CreateOptionalDefaultSubobject<UPaperFlipbookComponent>(this, ComponentName);
if (BodyPart)
{
BodyPart->AlwaysLoadOnClient = true;
BodyPart->AlwaysLoadOnServer = true;
BodyPart->bOwnerNoSee = false;
BodyPart->bAffectDynamicIndirectLighting = true;
BodyPart->PrimaryComponentTick.TickGroup = TG_PrePhysics;
BodyPart->SetupAttachment(this);
static FName CollisionProfileName(TEXT("IgnoreOnlyPawn"));
BodyPart->SetCollisionProfileName(CollisionProfileName);
BodyPart->bGenerateOverlapEvents = false;
}
// ...
}
The problem is that when I try to run code on the FlipbookComponent, it shows up as a NULL object. Am I forgetting something simple? Do FlipbookComponents not work when added to a SceneComponent?