Mutable Item Stack

Zaddo

Active member
I am trying to implement a custom mod in UIS that will allow Mutable/Common items that are stacked, to have Item Attribute values set for each stack. For example, I have two stacks of apples that will go rotten after a period. I want an attribute on the Item that tells me how old that stack is. But each stack needs to have its own value for the attribute. I have asked previously and you advised UIS can't do this natively.

When I load the inventory, I set the attributes for the item in a stack to its specific value. And I can see in the debugger, that the item for each stack has different attribute values.

But when I let the code run, and next time look at the attribute value on the item, they have all been set to the same value.

I cannot find what is changing these attribute value's so they stay the same on all stacks. Could you please point me at the code that keeps the attribute values synchronised or explain how this works?

Thanks in advance.

In case what I am trying to do isn't clear. Hear is a short video, trying the set the values on two stacks to different values in the inspector.
 
Last edited:

Sangemdoko

Moderator
Staff member
If you have a closer look at the ID of the apple you'll see that you are actually referencing the same Apple in both stacks. That's one of the things to be careful about when using Mutable/Common items. The system won't automatically change the ID when added to ItemCollection like it does with Unique items, because you might actually want both stacks to reference the exact same Item such that they can be merged.

You'll probably want to make a custom ItemCollection such that you can decide when and when not to create different Item references. Especially when it automatically creates a new stack when it overflows.

Another option is to keep the items as Immutable/Common and keep the Durability (and other values) somewhere else. Either asociated to an index or some other data such that you can cross reference the stack with that value. But in that case you'll have a lot of problems when splitting stacks, etc...

I hope that points you in the right direction. I'll add your use case in my notes such that I don't forget. And if I ever come up with a better solution I'll let you know
 

Zaddo

Active member
If you have a closer look at the ID of the apple you'll see that you are actually referencing the same Apple in both stacks. That's one of the things to be careful about when using Mutable/Common items. The system won't automatically change the ID when added to ItemCollection like it does with Unique items, because you might actually want both stacks to reference the exact same Item such that they can be merged.

You'll probably want to make a custom ItemCollection such that you can decide when and when not to create different Item references. Especially when it automatically creates a new stack when it overflows.

Another option is to keep the items as Immutable/Common and keep the Durability (and other values) somewhere else. Either asociated to an index or some other data such that you can cross reference the stack with that value. But in that case you'll have a lot of problems when splitting stacks, etc...

I hope that points you in the right direction. I'll add your use case in my notes such that I don't forget. And if I ever come up with a better solution I'll let you know

Thank you very much. I thought about storing the value in another location, but you made the UI so nicely integrated with the Attribute values, I like how this works and I don't want to mess with it.

I am already using a custom collection for the shape grid. Most of the updates to the collection go through my server code, and so the traps you mentioned are not there in my setup. I think this will not be too difficult to change. Thanks for the tip, this was the piece of information I needed :)

EDIT:
That was a lot easier than I thought it was going to be. I just had to override the AddItem method so that it doesn't reassign the Item on Mutable items when it creates a new stack. The two tomatoes below are showing different durability :)

1664788832920.png
 
Last edited:
Top