Don't drop currently equipped items

I have items that enemies drop which a player can pick up in my game. These are stored as actor variables in the character.

I want to be able to stop an item that a player has equipped from dropping again when an enemy is killed (no duplicate items). I tried doing this by setting the actor (item) as a variable in the enemy, and if the actor the enemy would drop is equal to the actor equipped by the player, dont drop. This failed so i tried matching the name of the actor using a wild card. If the name of the actor matches BP_itemname* = dont drop.

Im about out of hair to pull out. Any suggestions would be appreciated.

Don’t forget an actor is an instance, first spawn is Item_0, second spawn is Item_1.
so that why your comparison isnt working.
You can also use GetClass to solve that.

Or
Do you have some sort of data tables for your item ?
for example, try to compare using ItemID, a variable Name from your itemBP.

Thanks for the input. I have effectively used wildcrds in other BPs and it works. So the wild card looks for the name of the BP that is dropped, and assuming that name is BP_item, then it drops the first time it may be just that. But if it drops a second time maybe it is bp_item1 (like you describe. Since the wildcard is looking for BP_item* i assume that the asterisk covers anything that comes after the word item right?

I am not using any data tables, since the items that i am trying to do this are not numerous.

Get class is something i have not tried. I use the class of the item to save and load the items to the character when the game quits and restarts and it works well, so you may be onto something here.

So in this case, lets say i set the item as a variable in the enemy and then use get class to save the class of that item. Would i then get the actor from the character that is equipped, get class of it, set it as a seperate class variable too, and then if the class of the droping actor equals the class of the character item equipped variable, dont drop? Or is there another method?

an ItemID type approach is not really bound to DataTables, they can be used with DataAssets, just plain structs (mainly because DataTable is a fancy wrapper holding DataTableRows which are structs, and DataAsset is a way to create Structs nearly Raw in the Content Browser/Drawer)

both of these are scalable from 5 “things” to 500 “things”, but I would argue that DataTable is more scalable because you don’t need to instance an object to do a compare.

what either DataTable or DataAsset allows is so that you can look at information about the Blueprint without having to create the actor to do so. which Spawning an Actor just to look at one of its Members to then destroy it can lead to stutters, the Garbage Collector being flooded with requests, and in the worst case of the Garbage Collector not getting everything in its passes a potential Paging situation.

I am don’t know your actual implementation, but here is an implementation that would use a Map for looking up the Spawn:
I have a Map that has <int ItemId, BP_Item Item> then when I go to spawn the item onto the “Enemy” which will have an array of ItemID (it could have only 1 but array has higher scaling and versatility) for the potential drop.
Then after the “ItemID” has been designated the candidate look at the items the “Player” already has to see if that “ItemID” is already there.
if the “ItemID” is not found then I would go to that Map/DataTable, using the ItemID to get the Blueprint, and spawn it then

if there is to be many “things” in the Map/DataTable then I would suggest going with Soft References to lower memory footprint at least early on.
this approach also allows for you to do additional logic around like Upgrades, where you could have specific ItemIDs check against others as well, for example if basic sword is ItemID=7 and Sword2 is ItemID=13you can implement that logic with a system like this.

1 Like

You can do this either via the comparision with the GetClass or simply add a Variable NameID:

For a large number of item, like gardian suggested, it better to go with a DataTable or DataAsset.

I appreciate all of the excelent input from both you and guardian. I dont have a significant number of item for which I need to do this. Not more that 100, but they are all different types, so groups of less than 20 items.

I am going to take a crack at the option to try and get class and see what i can get out of it. I feel like it will work since ive used something similar to your suggestion in other ways. Ill let you know how it all works out.

@gardian206 - thank you for the very detailed method. If i have no success with Arodi007’s method, ill start the work of seeing if i can get yours to work. I appreciate it very much!

1 Like

I thought I had this licked but apparently, I’m still missing something. I should probably add some more color here. all of the items being dropped are children of a single parent. When implementing as you showed above, my drops all look like this:

Essentially, I have a reference to my player stored in the enemy. From there, I can get “equipped bangle.” Once the bangle is dropped in the enemy BP, it creates the variable of that item. If I equip it, then it makes sense that variable “w1” should now match the equipped bangle from the player.

In the image above, I have what seems logical. If the match is false, drop the item. However, the enemy will only drop the item if I use the true branch. After that, the enemy will not drop any other item. If i keep it on the false branch, enemies drop nothing at all. Would that be because the class is looking to the parent, and since they all share the same parent, it will not drop?

is your variable w1 and bangle of type Actor ?

you can test with a print string to check the values whether they are valid or not.

might be easier with the 2nd method using itemID variable for each child bp item.

Well the variables for the items are coming from a spawn actor node, and all of the items being dropped are of typr actor. I would assume they are but who knows what unreal does some times :rofl:

Ill play around with item id and see what i can come up with. Thank you for sticking with it! I appreciate the help!

1 Like

sure, good luck :innocent:

and don’t forget to test with Print String