The solution was to:
- Make everything
UPROPERTY(Transient)
. - Initialize
UStorage
in BeginPlay() withNewObject<USlotStorage>(this)
.
But why has this to be initialized dynamically inside BeginPlay()
if it does not access any Blueprint data? Wouldn’t it load faster at runtime if it is initialized at compile time?
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class THETHIRDPERSONGAME_API UInventoryComponent : public UActorComponent
{
GENERATED_BODY()
// ...
private:
UPROPERTY(Transient) TObjectPtr<USlotStorage> ShotgunShells;
USTRUCT(BlueprintType)
struct FStorageInfo
{
GENERATED_BODY()
// ...
UPROPERTY(Transient) int Count = 0;
void UInventoryComponent::BeginPlay()
{
Super::BeginPlay();
// ...
ShotgunShells = NewObject<USlotStorage>(this);
ShotgunShells->Init(this, InventoryLayout.ShotgunShells);
}