Inherited Members are always NULL/0 in the Derived Class

Hi Guys,

So basically inheriting a member is always null/0 in derived class.

Base class:

float damageToDeal = 100.f; // Base class.cpp

Derived class

GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, FString:FromInt(damageToDeal)); //is always 0.

This applies to every single inherited variable. The only way to get it to work is reinitialize the variable in the derived class like so:

damageToDeal = 100.f; //Derived class .cpp

This applies to pointers etc, I have been stuck on this for quite a while and would appreciate if someone could guide me on this issue. This applies to both UPROPERTY and non UPROPERTY.

Thank you,

This is (obviously) not the correct behaviour. Could you provide some more information. For example when are you setting damageToDeal to 100? And where are you printing it out?

So damageToDeal is set in PostInitializeComponents (To make use of editor settings). And in the Derived Class its also in PostInitializeComponents, I even tried BeginPlay but it is always 0; EDIT: I even set it on server and set it to Replicated, but nothing.

It because reflection system takes varables defaults (Which you set in editor) from class constructor, when you set it somewhere else (since you said you set it in PostInitializeComponents) the variable wont be stored in default object (CBO) and reflection system won’t restore it properly in derived class and probably other situations too.

But how do I go about inheriting Editor values as well? Since setting the value in Base Constructor (Using editor values) is always going to be null until PostInitializeComponents. Am i simply forced to reinitialize every time?

I had this issue with SettingTheSpellCaster pointer a few weeks back (which makes alot more sense of why it was not working in derived classes).