Basic item system not recognizing multiple items in collision area

I couldn’t think of a good title, but basically what I have on my character is a capsule collider that is the pickup area, any items that collide with it can be picked up, when that collider is overlapping with my pickup parent actor it lets me know that there is an item that can be picked up, and when the use key is pressed it will let me know that the item has been picked up and it will destroy the actor, all of that works well and as intended, unfortunately there is a problem when there is more than one item inside the pickup collider, while it does seem to know that there is more than one item there, it will only destroy one when use is pressed, to destroy the other I will have to reset the overlap by moving away and going back again…

You can see from those screenshots that it’s nothing really complicated, Is it possibly because the OnComponentBeginOverlap node doesn’t refresh every tick and is only fired once the overlap takes place?

I can’t really think of a way to get around this, so any help or pointers would be very much appreciated.

Hi Recker,

I think it might be easier if, instead of using a Pickup bool, you instead add the OtherActor/Target to an array/list of actors during BeginOverlap. Then when you press the button, you iterate through your list destroying all the actors in it?
You would also need to remove the OtherActor/Target from the array during EndOverlap too.

Andrew

Okay cool I’ll try that, would it be possible if you could do up a basic one to show what you mean, I am still very much learning the blueprint system…

If not thanks anyway, I will attempt it by myself regardless.

Alright so I sorta got it working, unfortunately now it deletes both items at the same time, is there a way to cycle through them one at a time?

You could perhaps use a ForEachLoopWithBreak, and have the arrow coming out of Destroy Actor feed into Break - that way it’ll stop iterating after it’s destroyed the first one(?)

Andrew

EDIT: Also, you shouldn’t need your Pickup bool now, you should be able to remove that and the Branch condition to clean the blueprint up a bit (just incase that’s still affecting anything). You could just move the Print String to after the Destroy Actor node.

I’ve just tried that, and it seems to have the same results as I originally had, it won’t delete the second one until I have ‘left’ it and come back again, reinitializing that overlap.

Can you show me a picture of the latest (full) version of the blueprint (with the Pickup bool removed too) - if that still isn’t working, please?

This is a quick version I’ve just knocked up. Each individual key press results in the user picking up an item. Are you sure both your items are Tagged correctly? It may be worth stripping your blueprint down to it’s simplest implementation to see if there’s anything unnecessary that’s affecting it.

Andrew

That works, thanks a bunch, it was because I wasn’t removing the index on end overlap it would stack up the index number and it seems that it always deletes the first index with the for each loop.

Thank you so much for this, I don’t really understand arrays that much, I looked at the documentation but I’m not finding it really clear, oh well eventtually I will get it.

No problem, Recker :slight_smile: Yes, each time a ForLoop node is reached it’ll start iterating again from Index 0 and although you are destroying the actor from the world it’ll still be taking up space at Index 0 in the array unless you remove it too.

Glad I could help

Andrew