Last improvements on the save front

This commit is contained in:
Michal Pikulski
2025-11-05 17:34:26 +01:00
committed by Michal Pikulski
parent b3e0f90e09
commit 64253c1048
14 changed files with 610 additions and 176 deletions

View File

@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using System; // for Action<T>
@@ -357,7 +357,27 @@ namespace Interactions
// Try to find the item in the scene by its save ID via ItemManager
GameObject slottedObject = ItemManager.Instance?.FindPickupBySaveId(slottedItemSaveId);
if (slottedObject == null)
if (slottedObject == null && !string.IsNullOrEmpty(expectedItemDataId))
{
// Item not found in scene - it might be a dynamically spawned combined item
// Try to spawn it from the itemDataId
Debug.Log($"[ItemSlot] Slotted item not found in scene: {slottedItemSaveId}, attempting to spawn from itemId: {expectedItemDataId}");
GameObject prefab = interactionSettings?.FindPickupPrefabByItemId(expectedItemDataId);
if (prefab != null)
{
// Spawn the item (inactive, since it will be slotted)
slottedObject = Instantiate(prefab, transform.position, Quaternion.identity);
slottedObject.SetActive(false);
Debug.Log($"[ItemSlot] Successfully spawned combined item for slot: {expectedItemDataId}");
}
else
{
Debug.LogWarning($"[ItemSlot] Could not find prefab for itemId: {expectedItemDataId}");
return;
}
}
else if (slottedObject == null)
{
Debug.LogWarning($"[ItemSlot] Could not find slotted item with save ID: {slottedItemSaveId}");
return;
@@ -382,12 +402,16 @@ namespace Interactions
if (slottedData == null)
{
Debug.LogWarning($"[ItemSlot] Pickup {pickup.gameObject.name} has null itemData! Expected itemId: {expectedItemDataId}");
if (slottedObject != null)
Destroy(slottedObject);
return;
}
}
else
{
Debug.LogWarning($"[ItemSlot] Slotted object has no Pickup component: {slottedObject.name}");
if (slottedObject != null)
Destroy(slottedObject);
return;
}