splinedrew
Member
Hello there!
I have a bunch of objects placed around the world. I am making an editor function for myself that adds these items into an inventory. The idea behind it is if we are starting a new game, it will populate the world from the load out inventory ("Game Start"). If it is not a new game, it will generate the trees based on the saved inventory of trees. The problem I have is that the ItemObject on each game object is set up properly but the custom attributes are not saved into the inventory. Instead it reverts the attributes to default settings.
I have a bunch of objects placed around the world. I am making an editor function for myself that adds these items into an inventory. The idea behind it is if we are starting a new game, it will populate the world from the load out inventory ("Game Start"). If it is not a new game, it will generate the trees based on the saved inventory of trees. The problem I have is that the ItemObject on each game object is set up properly but the custom attributes are not saved into the inventory. Instead it reverts the attributes to default settings.
C#:
public void CheckInSelection()
{
ItemObject[] placedItems = GetItemObjects(Selection.gameObjects);
if (placedItems != null)
{
if (placedItems.Length > 0)
{
m_Inventory.Initialize(true);
ItemCollection startCollection = m_Inventory.GetItemCollection("Game Start");
for (int i = 0; i < placedItems.Length; i++)
{
var item = Opsive.UltimateInventorySystem.Editor.VisualElements.ItemField.CreateItem(placedItems[i].Item.ItemDefinition);
var positionAttribute = item.GetAttribute<Attribute<Vector3>>("Position");
if (positionAttribute != null)
{
positionAttribute.SetOverrideValue(placedItems[i].transform.position);
}
var rotationAttribute = item.GetAttribute<Attribute<Quaternion>>("Rotation");
if (rotationAttribute != null)
{
rotationAttribute.SetOverrideValue(placedItems[i].transform.rotation);
}
placedItems[i].SetItem(item);
EditorUtility.SetDirty(placedItems[i]);
if (startCollection.DefaultLoadout == null)
{
startCollection.DefaultLoadout = new ItemAmounts();
}
ItemAmount newItem = new ItemAmount(item, 1);
startCollection.DefaultLoadout.Add(newItem);
}
m_Inventory.Serialize();
EditorUtility.SetDirty(m_Inventory);
}
}
}