How can i add "look at object" as an condition when picking up an object?

Hi! I’m doing the UMG Inventory tutorial and was just wondering that how can i make it that it would also require me to also look at the object when picking it up? now i pick it up when ever i’m within the area and press “E” and this will cause problems when dealing with multiple objects within small area.

Was thinking about something like that. Thanks mate! have to start looking into that :slight_smile:

Fire a line trace from the camera when you are in the area and compare the hit result of the trace with the object.

I did it and it kinda works, now the problem is that how do i assign it to understand when it’s looking the right object. Is there some neat way to do it or do i have to build a huge pile of blueprints to cover all objects (i hope and expect that that’s not the case)? Thanks in advance!

How have you set the part right after the trace in your BP? You would normally get the class of the hit actor and then compare it with the class of the BP you want to pick up.

Sorry but i’m really just trying to learn things and i do mostly 3D models so this isn’t my strength clearly…

But anyway this is the BP for my Single Line Trace.

And this is the BP for the pickup command, Should i implement the compare command on those?

It’s fine, i’m not really a programmer either but you’ll get used to BP’s(and sometimes have more fun) in no time.

Now, i dont know how you are setting the Object Looked bool, but here’s what you should do:

  • Drag from Hit Actor of th trace’s hit result
  • type Get Class
  • drag from the return value of the get class and type “equal” and you’ll get a node that compares if too classes are the same.
  • Select your pickup item as the class to compare
  • Now get that bool output and set the Object Looked bool with it right after the line trace.

Let me know if this is too confusing and i’ll post a screenshot.

Thanks for the fast answer. :slight_smile: actually the Object Looked boolean was left there accidentally, i tried to make it work like that and allready have deleted all the other components of that experiment. But i shall try it and post results. Your explanation looked very understandable :slight_smile:

You can use an OR node to connect those bools and then plug the OR’s output to Object Looked. This way it will be true if any of those conditions is true; otherwise false.

I did get it to work, but when one problem solves another one appears… How can i get the same thing to work with all of my objects?

Here’s a picture of what i did.

Haha, should have figured that one out. But now again i face another problem. it now works almost as intended but still one problem remains, now if i look at one object and there is another one of those in the area, it will pick up that also. It doesn’t pick different types anymore.
And mate i really appreciate the effort and patience you possess that exceeds the limits of the greatest zen master when helping me out. :smiley:

lol…I enjoy this, and i also hope that people i help will eventually help others too later on. :slight_smile:

However, the problem you are having now doesnt seem like anything i can help with i’m afraid. It sounds like a collision issue so make sure the collision boxes of those meshes arent larger than the meshes themselves. You can visualize collision in the viewport by enabling Player Collision in View Mode. And with console command show collision in game.

And i will help others if my skills at some point let me do so :slight_smile:
But basically what i want this to do is simply pick up only the item i am currently aiming with my line trace. When thinking of it feels that it shouldn’t be anything special because it’s pretty common game mechanics. Very possibly there is some easy solution for this and it also might be that the whole inventory/pickup thing i did by the tutorial just isn’t the best one for this kind of behavior. Well, just have to keep digging around :slight_smile:

Oh, i think i see. Try to use DoOnce after E pressed. If it still doesnt work execute the line trace after E pressed > DoOnce and then plug the line trace to the branch. Now it should select and pick only one item when you pick something up.

if all items are picked up the same way, they should all inherit from a base class that can be picked up. you don’t need to compare each of your item types, you can just compare the base class to know if it can be picked up.

try using a ClassIsChildOf node.