I have class derived from uobject
class GWGENERALS_API UGWArmor : public UObject
and variable
public:
UPROPERTY(BlueprintReadOnly)
FText ArmorType;
When the game starts, the variable is initialized and there is a value in it, I checked it with a debugger. But after about 10-20 seconds, the variable becomes nullptr and any access to it, for example ArmorType.ToString() causes an error. This behavior appears only in the packaged game. When game runs in the editor`s viewport, everything works fine and the text has value at every time
Solved. Ive marked class property FText ArmorType as UPROPERTY(BlueprintReadOnly) but didnt marked class owner UObject Armor as UPROPERTY. So not only FText was garbage collected, but whole owner uobject.
Adding to root is a bad way to do it, unless you absolutely need that object to NEVER be garbage collected. Generally you want some sense of ownership (e.g., My Player owns their armor, so if my player ever is destroyed - it’s safe to destroy the armor as well).