diff --git a/Assets/Scripts/Movement/FollowerController.cs b/Assets/Scripts/Movement/FollowerController.cs index ddb48426..73d77dfa 100644 --- a/Assets/Scripts/Movement/FollowerController.cs +++ b/Assets/Scripts/Movement/FollowerController.cs @@ -65,6 +65,11 @@ public class FollowerController : MonoBehaviour private bool lastInteractionSuccess = true; + /// + /// Cache for the currently picked-up GameObject (hidden while held). + /// + private GameObject cachedPickupObject = null; + /// /// Set to true if the follower just combined items. /// @@ -329,31 +334,29 @@ public class FollowerController : MonoBehaviour if (justCombined) { // Combination: just destroy the pickup, don't spawn anything + if (cachedPickupObject != null) + { + Destroy(cachedPickupObject); + cachedPickupObject = null; + } GameObject.Destroy(pickup.gameObject); justCombined = false; break; } // Swap logic: if holding an item, drop it here - if (currentlyHeldItem != null) + if (currentlyHeldItem != null && cachedPickupObject != null) { - var basePickupPrefab = GameManager.Instance.BasePickupPrefab; - if (basePickupPrefab != null) - { - var droppedPickupObj = GameObject.Instantiate(basePickupPrefab, pickup.transform.position, Quaternion.identity); - var droppedPickup = droppedPickupObj.GetComponent(); - if (droppedPickup != null) - { - droppedPickup.itemData = currentlyHeldItem; - droppedPickup.ApplyItemData(); - } - } - else - { - Debug.LogWarning("BasePickup prefab not assigned in GameSettings"); - } + // Drop the cached object at the pickup's position + cachedPickupObject.transform.position = pickup.transform.position; + cachedPickupObject.transform.SetParent(null); + cachedPickupObject.SetActive(true); + cachedPickupObject = null; } SetHeldItem(pickup.itemData); - GameObject.Destroy(pickup.gameObject); + // Cache and hide the picked up object + cachedPickupObject = pickup.gameObject; + cachedPickupObject.SetActive(false); + cachedPickupObject.transform.SetParent(this.transform); break; } }