Blueprint Default Values Diverge from C++ Class Definitions

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:

  1. Why is this happening?
  2. 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);
}

You are trying to alter inherited values hence why in begin play it works as expected so either define a property that can be edited or super the onconstruction or create a method that you can call to set values

Thanks for the suggestion here! To test this, I had moved the SetCollisionObjectType (and all other collision settings) into the SProjectile class (rather than MagicProjectile`). I still encounter the same issue.

To make it even simpler, I even created a Blueprint based off of SProjectile class and I still see the same behavior.

If the problem is caused by inheritance, shouldn’t that change resolve the issue?

yeah but because in the parent the values are set in the constructor it will require overriding it in the onconstruction or constructor without viewing it more closely, but i would say have a quick look at some c++ collision inheritance vids just to see what I mean