How to make object destroyed when 'picked up' and spawn when 'dropped'

Hey all ^^

I’m currently looking for a way to have my 2D sprite character pick up and drop a carryable object! :smiling_face:

I tried this with the most conventional method of attaching the object to the player, but this had some unforeseen issues with the object appearing in-front and behind the player, and the animation looked janky as the object remained in a fixed position, rather than bobbing like the idle/ walking player.

Here is the previous code for this system:

My new idea was to create pixel sprite animations of the player holding the item, and use these instead, as they gave me more creative freedom.

I feel that these animations work a lot better, but now I need to be able to destroy the object when ‘picked up’ (then the carrying animation will play), and spawn in the object when ‘dropped’ (the animations will return to normal). The player must also not be able to pick up more than one object at a time.

I already have the animations sorted, but I’m not sure how best to tackle the spawning and destroying! Essentially, its like a basic inventory system?

I’m more so a designer than a developer, so beginner-friendly language is much appreciated! ^^

Here are some screenshots to show the current state of the mechanic:


And here’s a video to show more of the code, and the mechanic previously (before the animations that include the object). This might be useful to show what the problems were with the previous method!
Here’s the video!

Thanks so much for reading!

If you have any suggestions that are other ways of tackling the problem, feel free to leave them as well! It doesn’t have to be this spawn/destroy method if there is a better way of dealing with it! ^^

The problem is, you need your attachment point to move with the character. I know virtually nothing about 2D though… Also, naturally, when you enable physics, the item will drop.

It might be a good way to go, with animations, if you like that idea.

When you pickup ( and destroy ), store the class of actor in a variable. Then run the correct animation. When you put down again, discard the anim, and spawn from the stored class.

Rather than having lots of code to decide which anim goes with which class, you could use a map variable type, where each class is mapped to an anim. Much easier to use.

Hi, thanks so much for your help! I ended up abandoning this method as I felt this way was a little bit too complicated and decided to try a basic inventory approach instead? Although I am still having some issues (I have started a new question/ topic, I’ll put the link below!)
Thanks again for the help!

Inventory system with one slot? - Programming & Scripting / Blueprint - Epic Developer Community Forums (unrealengine.com)