ASTUBaseCharacter::ASTUBaseCharacter(const FObjectInitializer& ObjInit)
: Super(ObjInit.SetDefaultSubobjectClass<USTUCharacterMovementComponent>(CharacterMovementComponentName))
{
// Other Initialization
HealthComponent = CreateDefaultSubobject<USTUHealthComponent>("HealthComponent");
// Other initialization
}
It was working at first, then after some unknown manipulations and a couple of compilations it stopped working, then it lost it’s Details window, it’s just empty now and search in Root component doesn’t show properties either.
I tried to log everything during Play and that’s what I got: HealthLog: Display: HealthComponent.BeginPlay(), my UID is 27903 HealthLog: Display: SetHealth 100.000000 BaseCharacterLog: Error: BP_STUBaseCharacter_C_0 HealthComponent is null BaseCharacterLog: Error: BP_STUBaseCharacter_C_0 Found HealthComponent EXISTS: Uid = 27903
Component clearly exists, it’s being created and initilialized, it can be found on actor with GetComponentByClass(), but UPROPERTY is still being null.
One of fixes that worked is removal of UPROPERTY, compiling and adding it again. But after some time the bug is still happening. Maybe anyone knows the workaround to permanently fix it?
Sometimes, changes in the C++ source breaks things inside the Editor. In my experience with the Unreal Engine, Hot Reload (i.e. compilation from within the Engine) does not always work as expected. I am unaware of the exact reason/s as to why this happens, but have a few guesses.
The solution is to close the Editor, build the project using your IDE and then starting it up again. Ideally from within the IDE with the debugger attached.
I experienced this bug several times in the last days and collected some more information.
1. TWO different characters reference ONE component which is not being initialized btw:
2. Some rough explanation of why previous case is happening (code from Actor BeginPlay()):
Looks like broken serialization in editor, Blueprint has pointer to invalid data, can be actually related to hot-reload.
Oh, this bug. I have one property that keeps doing this. Luckily, it’s usually the actor instance that for some reason sets it to null. So there’s a little reset arrow besides it to put it back to default value and that fixes it for a while.
This is in the outliner to get the instance, not the main class or BP.
I can’t explain exactly what happened but it seems that the blueprint was “overriding” the C++ class value using weird cached values.
What worked in my case was to recompile the C++ class without the component, reload the blueprint, add the component again in C++ and, finally, reload the blueprint again.