Property not being set in code or blueprints

Good Day,

I have just migrated my project to 4.8 (its not a critical project) but I have run into an unusual bug.

I have set my property in my header file as such:

UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Bomb)
float ExplosionDamage;

and in my constructor in my source file I set is like so:

// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;

BombMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BombMesh"));
RootComponent = BombMesh;

sphereCollision = CreateDefaultSubobject<USphereComponent>(TEXT("SphereCollision"));
sphereCollision->SetSimulatePhysics(true);
sphereCollision->SetSphereRadius(explosionRadius);
sphereCollision->AttachTo(RootComponent);

BombExplosion = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("BombExplosion"));
BombExplosion->bAutoActivate = false;


//projectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));

fuseTime = 3.0f;
ExplosionDamage = 30;
UE_LOG(LogTemp, Warning, TEXT("Damage = %d"), ExplosionDamage);

In order to give it a default value. However when I set up a log point directly after that it returns 0, telling me that it has not been set at all. It gives the same result in BeginPlay().

I also noticed that even if I use a hard coded 30 damage into the TakeDamage function like so:

testActor->TakeDamage(30, DamageEvent, GetInstigatorController(), this);

The ReceiveAnyDamage event does not fire. Was this changed somehow for 4.8?

Where do you call UE_LOG and TakeDamage?

I call UE_LOG immediately after initialising the variable in the constructor, it still returns 0. Take damage is when the bomb explodes and should send a “damageRecieved” event, but it doesn’t (because the damage passed is being read as 0, even when hard coded)

Well checking varables in constructor might give odd results, so you should check it in BeginPlay. When you create blueprint from this class do damage is properly set in defaults? Maybe paste whole constructor

It gives the same result when I call it inside BeginPlay(). Updated the constructor code. I do not alter the value anywhere in the code, its only given a default value and then I can adjust the damage in the blueprint.

Checking variables in the constructor is perfectly fine - C++ would be pretty unusable if that would not be the case.

However “ExplosionDamage” is of type “float” and your UE_LOG prints out that float as an “int” because you are using “%d”. So this will give you wrong output at least.

Why not just set a breakpoint and check what the Debugger tells you about that variable?

Also, just step into the TakeDamage() code and see what is happening. As you can see the damage may get modified by InternalTakePointDamage() or InternalTakeRadialDamage(). If the “Actual Damage” ends up with 0, the “ReceiveAnyDamage” event will never be called.

Marc

Thank-you for pointing out the error in my UE_LOG, I didn’t read the docs correctly on that, after reading them again and changing it, I am getting the correct readout now, I will go through the TakeDamage code and see what is happening there.