I posted another question here https://answers.unrealengine.com/questions/737973/reference-being-added-to-defaults-container.html which is likely related and sharing the same root cause.
In short, I have a custom UActorComponent called UCreatureActionHandler (to handle actions as objects determining what is currently being done and what can and cannot be done by my character) being added to my custom ACharacter class, and using the UPROPERTY specifier in the variable declaration seems to cause sporadic, hard to track issues (mainly the component being null in BP, but also the above linked bug).
My code is as follows:
//In ABaseCreature_Masterclass.h
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Components") //This line is the problem
UCreatureActionHandler* CreatureActionHandlerComponent;
//ABaseCreature_Masterclass.cpp
ABaseCreature_Masterclass::ABaseCreature_Masterclass()
{
PrimaryActorTick.bCanEverTick = true;
CreatureActionHandlerComponent = CreateDefaultSubobject<UCreatureActionHandler>(FName("CreatureActionHandlerComponent"));
}
The component UCreatureActionHandler is a simple C++ component inheriting from UActorComponent with default constructor, tick, and beginplay that comes with the class (there is more code but I commented everything out in the process of trying to find what was causing the bug, with no luck). As it stands now, the component does not have anything added to it that could cause an issue.
The problem presents itself in the form of the CreatureActionHandlerComponent variable being null. In the Blueprint defaults the window will be empty and blank when the component is selected and trying to get a reference to it via BP will return nullptr. However the component itself is working and present (e.g. printing from its tick function will show up), but the variable in the character is wiped clean.
A few quirks I have noticed:
-Changing the name of the variable will temporarily fix it (has lasted several weeks before) but it will break again whenever changes are made (exactly what changes I am unsure of)
-Changing any specifiers of the UPROPERTY in the variable declaration will temporarily fix it (usually until the next engine restart)
-Seems more prone to breaking if delegates are added, removed, or altered (altering delegates may also fix it until next compile/restart)
If I remove UPROPERTY from the variable declaration in ABaseCreature_Masterclass.h the component will work fine (but not be blueprint accessible in the same way, of course). This is a temporary fix that works but is not ideal since it makes it more annoying to work with the component. I have also noticed that I am not alone having this issue: Unreal Engine Issues and Bug Tracker (UE-18284) is similar (though mine is not caused by a class change) and https://answers.unrealengine.com/questions/734317/custom-uactorcomponent-is-null.html who also found that removing UPROPERTY fixed the issue.
I have tried replicating this in a fresh project but I have had no luck with it (which is why I didn’t post this as a bug report). However I have quadruple checked everything and there is no code affecting this component and its variable in the character that is not present in my replication attempts. While I could migrate the entire project to a new blank slate, it would be quite cumbersome not to mention there is no telling if the issue may return in the near future or not regardless.
I have tried basically everything by now, and while I could circumvent this issue by removing the UPROPERTY specifier it also makes it considerably more annoying to work with delegates in the component.