Hi,
Quick question I hope. I couldn't track down how to update the AmmoData attribute override value. Is the example below the correct method?
It is unusual because AmmoData is a Struct and the properties are readonly.
EDIT:
I did find this sample code (bottom of page, ItemAmounts), https://opsive.com/support/documentation/ultimate-inventory-system/attributes/
In this example the ItemSlots can be modified if the override value equals the GetValue(). But with the AmmoData, you cannot override, you always have to create a new instance? Is this correct?
Also, from my understanding of garbage collection and structs, the new struct will not add to garbage, because it is created on the Heap and when you update the override value, the values will map into the already allocated memory for the struct in the class?
Thx.
Quick question I hope. I couldn't track down how to update the AmmoData attribute override value. Is the example below the correct method?
It is unusual because AmmoData is a Struct and the properties are readonly.
EDIT:
I did find this sample code (bottom of page, ItemAmounts), https://opsive.com/support/documentation/ultimate-inventory-system/attributes/
In this example the ItemSlots can be modified if the override value equals the GetValue(). But with the AmmoData, you cannot override, you always have to create a new instance? Is this correct?
Also, from my understanding of garbage collection and structs, the new struct will not add to garbage, because it is created on the Heap and when you update the override value, the values will map into the already allocated memory for the struct in the class?
Thx.
C#:
int ammo = 5;
var ammoDataAttribute = item.GetAttribute<Attribute<AmmoData>>("AmmoData");
if (ammoDataAttribute == null) return;
AmmoData ammoData = ammoDataAttribute.GetValue();
if (ammoData.ClipRemaining != ammo)
{
ammoData = new AmmoData(ammoData.ItemDefinition, ammoData.ClipSize, ammo);
ammoDataAttribute.SetOverrideValue(ammoData);
}
Last edited: