Further updates to state machines
This commit is contained in:
committed by
Michal Pikulski
parent
199480447e
commit
b3e0f90e09
@@ -611,12 +611,14 @@ public class FollowerController : ManagedBehaviour
|
||||
newItem = Instantiate(matchingRule.resultPrefab, spawnPos, Quaternion.identity);
|
||||
var resultPickup = newItem.GetComponent<Pickup>();
|
||||
|
||||
// Mark items as picked up before destroying (for save system)
|
||||
// Mark items as picked up before disabling (for save system)
|
||||
pickupA.IsPickedUp = true;
|
||||
pickupB.IsPickedUp = true;
|
||||
|
||||
Destroy(pickupA.gameObject);
|
||||
Destroy(pickupB.gameObject);
|
||||
// Disable instead of destroying immediately so they can save their state
|
||||
// The save system will mark them as picked up and won't restore them
|
||||
pickupA.gameObject.SetActive(false);
|
||||
pickupB.gameObject.SetActive(false);
|
||||
|
||||
// Pickup the result (don't drop it!)
|
||||
TryPickupItem(newItem, resultPickup.itemData, dropItem: false);
|
||||
@@ -787,7 +789,8 @@ public class FollowerController : ManagedBehaviour
|
||||
|
||||
/// <summary>
|
||||
/// Bilateral restoration: Follower tries to find and claim the held item.
|
||||
/// If pickup doesn't exist yet, it will try to claim us when it restores.
|
||||
/// If pickup doesn't exist in the scene (e.g., dynamically spawned combined item),
|
||||
/// spawns it from the itemData.
|
||||
/// </summary>
|
||||
private void TryRestoreHeldItem(string heldItemSaveId, string itemDataId)
|
||||
{
|
||||
@@ -797,10 +800,30 @@ public class FollowerController : ManagedBehaviour
|
||||
return;
|
||||
}
|
||||
|
||||
// Try to find the pickup immediately
|
||||
// Try to find the pickup in the scene by SaveId
|
||||
GameObject heldObject = ItemManager.Instance?.FindPickupBySaveId(heldItemSaveId);
|
||||
|
||||
if (heldObject == null)
|
||||
if (heldObject == null && !string.IsNullOrEmpty(itemDataId))
|
||||
{
|
||||
// Item not found in scene - it might be a dynamically spawned combined item
|
||||
// Try to spawn it from the itemDataId
|
||||
Logging.Debug($"[FollowerController] Held item not found in scene: {heldItemSaveId}, attempting to spawn from itemId: {itemDataId}");
|
||||
|
||||
GameObject prefab = _interactionSettings?.FindPickupPrefabByItemId(itemDataId);
|
||||
if (prefab != null)
|
||||
{
|
||||
// Spawn the item (inactive, since it's being held)
|
||||
heldObject = Instantiate(prefab, transform.position, Quaternion.identity);
|
||||
heldObject.SetActive(false);
|
||||
Logging.Debug($"[FollowerController] Successfully spawned combined item: {itemDataId}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Warning($"[FollowerController] Could not find prefab for itemId: {itemDataId}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (heldObject == null)
|
||||
{
|
||||
Logging.Debug($"[FollowerController] Held item not found yet: {heldItemSaveId}, waiting for pickup to restore");
|
||||
return; // Pickup will find us when it restores
|
||||
@@ -809,7 +832,9 @@ public class FollowerController : ManagedBehaviour
|
||||
var pickup = heldObject.GetComponent<Pickup>();
|
||||
if (pickup == null)
|
||||
{
|
||||
Logging.Warning($"[FollowerController] Found object but no Pickup component: {heldItemSaveId}");
|
||||
Logging.Warning($"[FollowerController] Found/spawned object but no Pickup component: {heldItemSaveId}");
|
||||
if (heldObject != null)
|
||||
Destroy(heldObject);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user