jmackenzie68
New member
Greetings,
I am creating a harvesting system and I have run into an issue where the Inventory Pickup prefabs stop working after harvesting(destroying) the plant. I have tested the inventory pickup in my scene in other instances and it works fine except for when using it with my custom script.
My script is called in the Interactable script's OnInteract() event. When the plant is fully grown I can interact with it and the Inventory pickup prefab drops and the plant is destroyed. The pickup is set to auto interact, but nothing happens, well... I can kick it around the ground, just not pick it up! When I press the interact key I get the following error:
My script:
My Plant object:
The inventory pickup object that is create when interacting with my plant:
Please let me know if there is anything else I can provide to help solve this issue.
Thank you
Jared Mackenzie
I am creating a harvesting system and I have run into an issue where the Inventory Pickup prefabs stop working after harvesting(destroying) the plant. I have tested the inventory pickup in my scene in other instances and it works fine except for when using it with my custom script.
My script is called in the Interactable script's OnInteract() event. When the plant is fully grown I can interact with it and the Inventory pickup prefab drops and the plant is destroyed. The pickup is set to auto interact, but nothing happens, well... I can kick it around the ground, just not pick it up! When I press the interact key I get the following error:
MissingReferenceException: The object of type 'Interactable' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
Opsive.UltimateInventorySystem.Interactions.Interactable.Interact (Opsive.UltimateInventorySystem.Interactions.IInteractor interactor) (at Assets/Opsive/UltimateInventorySystem/Scripts/Interactions/Interactable.cs:172)
Opsive.UltimateInventorySystem.Interactions.InventoryInteractor.InteractWith (Opsive.UltimateInventorySystem.Interactions.IInteractable interactable) (at Assets/Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:156)
Opsive.UltimateInventorySystem.Interactions.InventoryInteractor.Interact () (at Assets/Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:106)
Opsive.UltimateInventorySystem.Interactions.InventoryInteractor.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/Interactions/InventoryInteractor.cs:96)
My script:
Code:
public void Harvest()
{
Debug.Log("Attempt to harvest" + gameObject.name);
if (currentPlantAge >= growTime)
{
if (isMultiHavestable)
{
//set crop back one level
//drop pickable crop
//possibly check how many times its harvestable
//check date/season for regrowth?
GetComponent<ItemDropper>().Drop();
}
else
{
GetComponent<ItemDropper>().Drop();
StartCoroutine(DestroySelf());
}
}
}
IEnumerator DestroySelf()
{
yield return new WaitForEndOfFrame();
if (ObjectPool.IsPooledObject(gameObject))
{
ObjectPool.Destroy(gameObject);
}
else
{
Destroy(gameObject);
}
}
My Plant object:
The inventory pickup object that is create when interacting with my plant:
Please let me know if there is anything else I can provide to help solve this issue.
Thank you
Jared Mackenzie