Hello everyone.
I have following class structure: Pawn → Character2D → Hero2D → Blueprint
Character2D class contains capsule component, flipbook component, custom movement component(derived from MovementComponent) and custom attack component(derived from ActorComponent).
They all declared in the header of Character2D class in the same way:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UPaperFlipbookComponent *FlipbookComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UCapsuleComponent *CapsuleComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class USimple2DMovement *MovementComponent;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
class UAttackComponent *AttackComponent;
This is how ACharacter2D() constructor looks like:
ACharacter2D::ACharacter2D()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true;
CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("RootCapsule"));
CapsuleComponent->bGenerateOverlapEvents = true;
CapsuleComponent->SetNotifyRigidBodyCollision(true);
CapsuleComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
CapsuleComponent->SetCollisionObjectType(ECC_Pawn);
CapsuleComponent->SetCollisionResponseToAllChannels(ECR_Ignore);
CapsuleComponent->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
CapsuleComponent->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Overlap);
CapsuleComponent->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
this->OnActorHit.AddDynamic(this, &ACharacter2D::OnHit);
RootComponent = CapsuleComponent;
FlipbookComponent = CreateDefaultSubobject<UPaperFlipbookComponent>(TEXT("FlipBook"));
FlipbookComponent->SetupAttachment(RootComponent);
FlipbookComponent->SetRelativeLocation(FVector::ZeroVector);
MovementComponent = CreateDefaultSubobject<USimple2DMovement>(TEXT("2DMovement"));
MovementComponent->UpdatedComponent = RootComponent;
AttackComponent = CreateDefaultSubobject<UAttackComponent>(TEXT("Attack"));
}
The problem I’m facing is that when I change code of my movement component, It detaches from the blueprint.
The “Details” tab of the movement component in the blueprint editor gets empty, when I spawn new instance of the blueprint on a level, this is what I see:
But this movement component is declared as a UPROPERTY.
Any usual measures like rebuilding the project/reparenting the blueprint do not work.
The only thing that works is creating a new blueprint and copy/pasting everything from the previous one.
But the bigger the project gets, the more annoying this process is.
Another interesting detail is that changes in my attack component get reflected in the bluepring without any issues.
Here is a part of attack component header:
#pragma once
#include "CoreMinimal.h"
#include "Attack.h"
#include "Components/ActorComponent.h"
#include "AttackComponent.generated.h"
UCLASS()
class FRANCIS_API UAttackComponent : public UActorComponent
{
GENERATED_BODY()
public:
UAttackComponent();
protected:
virtual void BeginPlay() override;
public:
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
void Attack();
FVector2D GetDash() const;
etc.
And a part of movement component header:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/MovementComponent.h"
#include "Engine.h"
#include "Simple2DMovement.generated.h"
struct F_Timer
{
float CurrentTime, TargetTime;
bool Expired()
{
return CurrentTime >= TargetTime;
}
F_Timer() : CurrentTime(0), TargetTime(0) {}
F_Timer(const float Target) : CurrentTime(0), TargetTime(Target) {}
};
UCLASS()
class FRANCIS_API USimple2DMovement : public UMovementComponent
{
GENERATED_BODY()
public:
USimple2DMovement();
virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
virtual void SetUpdatedComponent(USceneComponent* NewUpdatedComponent) override;
void SetHit(const FHitResult &Hit);
void AddDash(const FVector2D &Dash);
etc.
The only (probably) significant difference I see is a structure definition before movement component class declaration, but commenting of everything related to the structure does not solve the problem either.
Does anyone have any idea why movement component causes issues and attack component doesn’t?