Howdy y’all, I’m experiencing an issue in Unreal Engine 5.3 (although I suspect it may be an issue in older versions as well).
I have a SMagicProjectile
class (derived from parent class SProjectile
) with a SphereComponent
root. SMagicProjectile
initializes with specific collision responses (see code). When I make a blueprint derived from SMagicProjectile
, the Overlap collision settings shows correctly – but are considered non-default values (indicated by an arrow icon). Resetting those values changes the values from overlap
(the correct value as defined in the C++ code) to block
.
Interestingly, moving the Overlap
collision response setting to the BeginPlay
method makes the arrow disappear after recompiling. I’m looking for help to understand:
- Why is this happening?
- How can I fix this without relocating the collision setting code to the BeginPlay method?
Here is are relevant pieces of code below:
SProjectile.cpp
(parent class of SMagicProjectile
):
#include "SProjectile.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include <Components/SphereComponent.h>
ASProjectile::ASProjectile(float InitialSpeed, float InitialGravityScale)
{
InitializeComponents();
MovementComp->InitialSpeed = InitialSpeed;
MovementComp->ProjectileGravityScale = InitialGravityScale;
}
void ASProjectile::InitializeComponents()
{
PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bCanEverTick = true;
SphereComp = CreateDefaultSubobject<USphereComponent>("SphereComp");
RootComponent = SphereComp;
EffectComp = CreateDefaultSubobject<UParticleSystemComponent>("EffectComp");
EffectComp->SetupAttachment(SphereComp);
MovementComp = CreateDefaultSubobject<UProjectileMovementComponent>("MovementComp");
}
ASProjectile::ASProjectile()
{
InitializeComponents();
}
SMagicProjectile.cpp
:
#include "SMagicProjectile.h"
#include "GameFramework/ProjectileMovementComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include <Components/SphereComponent.h>
ASMagicProjectile::ASMagicProjectile() : ASProjectile(2000.0f, 0.0f)
{
SphereComp->SetCollisionObjectType(ECC_WorldDynamic);
SphereComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
SphereComp->SetCollisionResponseToChannel(ECC_WorldDynamic, ECR_Block);
SphereComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
SphereComp->SetCollisionResponseToChannel(ECC_Pawn, ECR_Overlap);
}