Question
Hello I’m trying to make save/load system in my game. I wrote InventoryComponent that has TArray like this.
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class GAME_API UInventoryComponent : public UActorComponent
{
GENERATED_BODY()
// skip unnecessary code
// ...
private:
TArray<FItemSlot> InventoryArray;
};
and initialize 5 default element in BeginPlay() or load SaveGame data. and when I save game, I copy InventoryComponent::InventoryArray to SaveGame::SavedInventoryArray.
UInventoryComponent::BeginPlay()
{
// load save game to CurrentSaveGame (skip code)
if (CurrentSaveGame)
{
InventoryArray = CurrentSaveGame->SavedInventoryArray;
}
else
{
InventoryArray.Init(FItemSlot(), 5);
}
}
void UInventoryComponent::SaveCurrent(UMySaveGame* CurrentSaveGame)
{
CurrentSaveGame->SavedInventoryArray = InventoryArray;
}
All is work clear at first time. but when I load save game from a slot, the engine gives me this warning.
LogUObjectGlobals: Warning: Failed to find object 'Object None.None'
Can I just ignore this? or did I miss something? please give me some advice.
one more curious thing is, I think TArray::operation= generate new memory. so in my code there are physically seperated 2 inventory array. but I want have only 1 inventory array. I tried TArray* SavedInventoryArray but it doesn’t compiled. and TArrayView isn’t solution for me. How can I syncronize InventoryComponent::InventoryArray with SaveGame::SavedInventoryArray? Should I copy whole array like that? I think it’s very waste of memory.
additional code
ItemSlot is just simple struct that has pointer and count value.
USTRUCT(BlueprintType)
struct GAME_API FItemSlot
{
GENERATED_USTRUCT_BODY()
public:
// all of variable is UPROPERTY
UItem* SlottedItem;
int Count;
};
Item is UPrimaryAssetData.
UCLASS()
class GAME_API UItem : public UPrimaryDataAsset
{
GENERATED_BODY()
// has FText for display name, FSlateBrush for icon.
};
and I wrote SaveGame class like this
UCLASS()
class GAME_API UMySaveGame : public USaveGame
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FItemSlot> SavedInventoryArray;
};
summary
-
why the enigne gives me LogUObjectGlobals: Warning: Failed to find object ‘Object None.None’ warning? How can I fix this?
-
How to send just reference of TArray to another TArray variable? no copy but just reference.