Picking Up Items With a Line Trace

I’m trying to pickup objects via a line trace originating from the player character.

Upon being hit by the line trace, I want an item or object to then allow itself to be picked up via a key press (for example, E) and display pickup text.

However, the item should only allow itself to be picked up for as long as the line trace is hitting it. Otherwise, it cannot be picked up and will not display pickup text.

I’ve already tried multiple variations of several solutions, but they either allow pickup and then never shut it back off, or they entirely don’t work.

What are working methods that would allow me to achieve this?

Here is a solution ( Made using First Person Tempate)

Assets :

66834-assets.png

FirstPersonCharacter BP :

MyWidget :

PickUp_BP :

Preview :

66839-pickuptest.gif

Yes that works, but it still only affects a single item or object. I need it to affect multiple items or objects. That’s been the main issue; a method either works for a single item or object, or it doesn’t work at all.

Make a master class for all items you will need to pick up. Then make each individual item a child of that master class. For your text, you could just say on hit, cast the hit actor to the master item class. If that works, then show the message, if not, dont show the message. The pickup itself could just simply be adding the item to an array, and hiding it in the world.

There are tutorials out there, and if you have the time I would suggest watching them. They helped me a lot.

Please do not answer with referrals, especially if you are not going to link to said referrals. If I had found an answer elsewhere, I would not be seeking an answer here. Furthermore, if I fully understood what you replied with, I would be able to solve my problem on my own.

Mhousse1247’s method works, but it only functions with a single pickup actor, and I need it to function with multiple, different pickup actors.

And so, my problem remains. I do not know how to translate the methods in which I am aware of (such as the method provided by Mhousse1247) so that it works with multiple pickup actors. And so, I reiterate my question: how can I use a single line trace to pick up multiple, different actors, individually?

There are 2 solution for this:

+) Use interface. Implement each pickup item blueprint with this pickup interface, then implement the pickup function. Then when your line trace hit some item, call the interface function, if that item did implement the pickup function, it will be picked up, else, nothing happen. Or instead of put the pickup function into individual pickup item blueprint, you can put it into your character blueprint, then use the pickup interface to check whether you can pick up that item by using a simple function that return a boolean value. Any pickup item blueprint that implement the function may return true, the other may return false, or something like that.

+) Inheritance and polymorphism (if you don’t know anything about programming, check out this link Introduction to Object Oriented Programming Concepts (OOP) and More - CodeProject ). Create a parent class, put the pickup function into that class, then create as many child class based on that parent class as you want, on the child class, you may change the static mesh, some effect function, description, override a parent function and so on. That way, when you line trace hit some some actor, cast that actor to the parent class and call the pick up function.

Note that i personally recommend polymorphism solution. And correct me if i wrong, but i guess you don’t have much experience with programming, and if it is true, either look for some programming guys to help, or read some book that teach you the basics of programming (function, variable, encapsulation, polymorphism, … basics stuff like that), either way will make your life easier if you want to advance further down your project.

Here is a solution using interface bp :

[Implementing Blueprint Interfaces][1]

Interface_BP + PickUpItem function :

FirstPersonCharacter BP :

PickUp_BP :

PickUp2_BP :

Test :

67120-test0.gif

Thank you Mhousse for your solution. This was actually quite simple to implement by following your BP screenshots.
I had a pickup system but it relied on capsule overlaps instead of a line trace. That actually worked great (A thin capsule protruding from the camera represented a line trace) BUT all pickup items overlapping the pickup capsule would be picked up instead of one item at a time which caused other issues.

I was easily able to implement this line trace into my pickup system and it works great for multiple objects, however I simplified it a little.

Instead of using the “item reference nodes” and the “isvalid” nodes I simply used the “Does Implement Interface” node connected to a Branch and plugged the pickup item message to the hit actor node on the break hit result.

I don’t need the pop up name widget for now, but it could be added to this in a similar way. The extra wires going off the right side of the screen are simply for other stuff and aren’t needed for the pickup line trace.

This works as scripted as long as you have the interface and proper event on the pickup item.

Hi, look, your first solution works for me, but, just like Frostycane, I wanted to pick more than 1 item. I followed every each step in those images, but, in “BreakHitResults” node, I can’t connect “HitActor” in “Set PickUpItemRef”.

This is an Image:

Sorry, ir’s written in Portuguese. Hope you can Understand

This is brilliant. You’ve all helped me so much!!! My inventory system was doing pretty well from the Epic tutorial video on YouTube, but I had altered it quite a bit for what I am doing. Recently I have been setting up line traces and this answered some questions for me.

So thank you! Appreciate it!!

nice post find job
https://jobsflyer.com