Dropping Items On Death

Nicky_g_

Member
Good Morning!

After some tinkering and reading I can't figure out how to get an NPC to drop items they pickup when they die or take damage. I have an NPC spider driven by a Behavior Designer behavior tree, its able to pickup items and add them to its UIS default main item collection. The thing I can't do is have it drop it so the player character can pick it up. I've tried the Drop script provided in UCC inventory section but its not working because line
"var item = inventory.GetItem(i, m_ItemType);"
needs an itemIdentifier instead of an int and I can't get it to work. I tried using the ItemDropper script from the UIS and that didn't work. I tried reverse engineering the UCC/UIS integration demo and I'm lost. I don't know what is calling the drop from the inventory.

How can I get a NPC that is using UCC and UIS to drop an item it has picked up on its death?

Thanks!
 
Just to clarify, does the spider equip the item the UCC way once it picks it up? Or does it simply add the item the UIS way within an item collection?

If the NPC uses the bridge component then all equippable items that are added to the main item collection will be sent to the equippable item collection. And from there the bridge will monitor that item.

From what I understand you only care about the spider being able to pickup and drop items without equipping them.

In the integration demo we have wooden boxes that drop items when destroyed. You can see the different ways to drop items (random, item, inventory, etc...)
1606918538691.png
It's important that the ItemCollection ID points to the correct ItemCollection either by name, purpose or both.
You do not have to add the item to the default item collection you could have a special Item Collection specifc for NPC pickup/drop


Now if you wish to drop an equippable item that is equipped the UCC way, then you must use do so from the bridge. I believe the easiest way is using the OnDropItemAction event

Code:
EventHandler.ExecuteEvent<ItemInfo>(itemInfo.Inventory.gameObject, "OnItemActionDrop", itemInfo);

I hope that helps you solve the problem
 
Thanks for the quick reply and it works now!

---For others that may have the same issue as me--

MissingLink.PNG
It did take me a bit to figure out what I was missing and it was how the Drop function is called on the Health script of the crate. By examining the Crate in the UIS/UCC Integration demo (not the stand alone UIS or UCC demos) it has a child component with a Health script. On the health script OnDeath needs to have Drop (which ever type) defined.

Works like a charm!
 
Last edited:
Top