Use "SaveSystem" to save the data in "Item".

KPDN

Member
I am currently using "SaveSystem" in the UIS to implement a system that saves dropped items and regenerates them after the game is loaded.

I use the drop object data structure in the UIS.
In the drop objects, "ItemObject" is used to store the drop object data, and "Item" is used to store the items.

So, how do I save the data of an Item?
If the "Item" data has not been modified, I can directly generate a new "Item" using "Item Definition".
However, if the "Item" data has been modified, how should it be saved?

Additionally, there is one point that I'm unsure about.
In the "Item Definition" section, what is the difference between "Item Definition Attributes" and "Default Item Attributes"?
I know there are differences between these two, but I need more information.
 
By default we do not have any way of saving dropped items.

We only save Inventories. Not ItemObjects.

So you'd either have to make your own Saver component, using the InventorySaver component as a point of inspiration.

What I would suggest is to keept track of all the items you drop in one Inventory. And save that. As well as saving the positions of the pickups.

Then when loading you could spawn those pickups at those positions and then get the item data from the Inventory.

I'm afraid, In all cases you will need to implement this yourself as it is not something we support out of the box



> In the "Item Definition" section, what is the difference between "Item Definition Attributes" and "Default Item Attributes"?

ItemDefinition Attributes are defined at edit time and cannot be changed at runtime since it is shared between all instances of those items.
Item Attribute are unique to the item instance (if the item is set to mutable), so for example you can have two "Bronze Sword" one with attack = 5 and another attack = 7.
Default Item Attributes is the value the ItemAttributes will use by default if you don't override them at runtime.

I hope that makes sense. More info in the docs:
 
OK, I got it. :) (y)
I also believe that "InventorySaver" has corresponding implementation methods, so I'm going to look for inspiration.
Furthermore, I think the framework of "SaveSystem" is quite good. I plan to expand upon "SaveSystem" and add more "Saver" functionalities.
 
By default we do not have any way of saving dropped items.

We only save Inventories. Not ItemObjects.

So you'd either have to make your own Saver component, using the InventorySaver component as a point of inspiration.

What I would suggest is to keept track of all the items you drop in one Inventory. And save that. As well as saving the positions of the pickups.

Then when loading you could spawn those pickups at those positions and then get the item data from the Inventory.

I'm afraid, In all cases you will need to implement this yourself as it is not something we support out of the box



> In the "Item Definition" section, what is the difference between "Item Definition Attributes" and "Default Item Attributes"?

ItemDefinition Attributes are defined at edit time and cannot be changed at runtime since it is shared between all instances of those items.
Item Attribute are unique to the item instance (if the item is set to mutable), so for example you can have two "Bronze Sword" one with attack = 5 and another attack = 7.
Default Item Attributes is the value the ItemAttributes will use by default if you don't override them at runtime.

I hope that makes sense. More info in the docs:
Svae:

Save.png

Load:Load.png

I checked "InventorySaver" and found that both "Save" and "Load" are carried out by saving and reading the "ID".
Does this indicate that if I have a sword with a durability of 4, which was created in the database and is only referenced in "Inventory", this sword has already been saved in the database, while "Inventory" merely holds the reference. When saving, only the ID needs to be saved. When reading, only by using the ID, the already saved item (a sword with durability of 4) can be obtained from the database?
So, does it mean that any item created from "InventorySystemManager" has already been saved in the database?
All that is needed is to obtain the reference from "InventorySystemManager" by using the ID, thereby retaining (with durability of 4) this attribute.
 
By default we do not have any way of saving dropped items.

We only save Inventories. Not ItemObjects.

So you'd either have to make your own Saver component, using the InventorySaver component as a point of inspiration.

What I would suggest is to keept track of all the items you drop in one Inventory. And save that. As well as saving the positions of the pickups.

Then when loading you could spawn those pickups at those positions and then get the item data from the Inventory.

I'm afraid, In all cases you will need to implement this yourself as it is not something we support out of the box



> In the "Item Definition" section, what is the difference between "Item Definition Attributes" and "Default Item Attributes"?

ItemDefinition Attributes are defined at edit time and cannot be changed at runtime since it is shared between all instances of those items.
Item Attribute are unique to the item instance (if the item is set to mutable), so for example you can have two "Bronze Sword" one with attack = 5 and another attack = 7.
Default Item Attributes is the value the ItemAttributes will use by default if you don't override them at runtime.

I hope that makes sense. More info in the docs:

I have a strange problem.

The function I implemented is to record the ID and quantity of the dropped items when the scene is closed. And when the scene is opened, the dropped items will be regenerated.

Now I create a scene, generate an "ItemObject" in the scene, and create an item with the ID "123123".
I save the ID and quantity, then close the scene.
After that, I reopen the scene, retrieve the item with the ID "123123" from "InventorySystemManager.ItemRegister.TryGetValue()" using the ID and quantity.
Now I can find "123123" and create it, but if I exit the "Play" mode and re-enter, I will find that it is impossible to obtain and create the item through "ID:123123", and it will prompt "Unable to find".

After that, I conducted tests using "Inventory" and "InventorySaver", and found that the items created in "Inventory" could still be retrieved again by their IDs after being saved and read.


I'm not sure where the problem lies. Using "Inventory" and "InventorySaver" can properly save and load. It seems that the items created using "InventorySystemManager" are not saved when exiting the "Play" mode.

My understanding is that for items created using "InventorySystemManager", the original versions are all saved by "InventorySystemManager". All that is needed to obtain a reference to the item is to retain its ID. So, when are the items created in "InventorySystemManager" deleted? Perhaps, the items I created were deleted without my knowledge, resulting in the "InventorySystemManager" failing to save the item with the "ID:123123" that I had created when saving.

please give your comment.
 
我遇到了一个奇怪的问题。


我实现的函数是当场景关闭时记录掉落物品的 ID 和数量。当场景打开时,掉落的物品将被重新生成。


现在我创建场景,生成场景中的“ItemObject”,并创建一个 ID 为“123123”的项目。

我保存 ID 和数量,然后关闭场景。

之后,我重新打开场景,使用 ID 和数量从“InventorySystemManager.ItemRegister.TryGetValue()”检索 ID 为“123123”的项目。

现在我可以找到“123123”并创建它,但如果退出“播放”模式并重新进入,我将发现通过“ID:123123”无法找到和创建该物品,并会提示“无法找到”。


之后,我使用“库存”和“库存保存器”进行测试,发现保存和读取后,库存中创建的商品 ID 还可以再次检索到。



我不确定问题出在哪里。使用“库存”和“库存保存器”可以正确保存和加载。似乎在“播放”模式退出时使用“库存系统管理器”创建的项目无法保存。


我的理解是,对于使用“InventorySystemManager”创建的项目,原始版本都由“InventorySystemManager”保存。获取项目引用所必需的是保留其 ID。那么,何时“InventorySystemManager”创建的项目会被删除呢?也许,我创建的项目被删除了,而我没有意识到,导致“InventorySystemManager”无法保存我保存时创建的“ID:123123”的项目。


请发表您的评论。

看来我已确定了问题所在。我在“InventorySaver”中忽略了一行代码:“SaveSystemManager.InventorySystemManagerItemSaver.SetItemsToSave(FullKey, listItemIDs)”。在“InventorySaver”中,似乎有些需要保存的项目 ID 需要单独提交给“InventorySystemManagerItemSaver”。我之前忽略了这行代码,我认为这就是项目无法正确保存的原因。我将进行下一步测试以验证。
This might be of some reference for others.

1770118278884.png
 
I went back to review the "Save System" documentation and found some clues here. Hahaha, but often, I always forget (just like when I used to study knowledge from textbooks in school). Hahaha
 
Hey KPDN

As you mentioned the InventorySaver saves the item id and the count.
But (just as you found out) it also tells
SaveSystemManager.IvnentorySystemManagerItemSaver
That it wants this item to be saved. This way if an item is referenced by many Inventories (or UI), its data is only saved once, no duplicate data.

So when loading we first load the item data of all items saved. And only then do we load the inventories by grabbing the already loaded item by id.

I hope that help clarify :)
 
Back
Top