Picking up objects in the world. A couple of questions that are perplexing me...

When looking into designing an interaction system for picking up objects, driving a vehicle, and speaking to characters, I came across a couple of things that I just can’t wrap my mind around. One of which is how exactly to modulize my interaction system when there’s so many different variables needed to be passed back and forth between the blueprints. I came to the conclusion that since my player and the vehicle will always be present in the world, I can safely cast between them on EBP and store the reference, but for objects like apples that I may find on the trail… Would I really want to cast? I just can’t wrap my mind around how to get the player to be able to find out if the object is a one or two handed object to play the correct animation while also attaching the object to the players hand socket. Should I be using components for object interaction?

I guess my main question is do I use my players collision to check for all overlapping actors and find who’s closest and call an interact interface on them? And if so then if it’s say an object on the ground how would it then communicate back what to do? Would I have a bunch of events in my character BP for climb in vehicle, pick up two handed object, pick up one handed object, etc and use the overlap and interface call to have the object display text to say “press E to interact” then have player check on interact button pressed what object it’s overlapping and execute the appropriate function to pick up etc?

In a Beat Em Up type game, i noticed a few things about picking up objects. It seems to “work” better if ran off an event tick checking is overlapping VS just an event on component begin overlap. I would just make an actor blueprint, an apple for example. And create a tall retangular collision box (taller seemed to work better, like just as tall as the player). To discern between a one handed or two handed object you could try actor or component tags. You might get away with logic in the item, or in the player, or both.

Hey @denickes!

What I usually do is put the interact function on a parent and have all of the items to be interacted with be a child of that interactable actor, so they’ll all have anything that parent does… and give it a function “F_Interact”, then override it on each new item and have that item do its unique thing.

So when you press your interact button: grab that focused actor, however you decide to do so, be it sphere trace, line trace, or what have you. Then cast to “Interactable” and run “F_Interact”. You can Override that function on any child of BP_Interactable_Parent.

You don’t want to cast to everything from the player because that forces the items to be held in memory as long as the player is, so you end up loading most of your game all at once and being really heavy.

Check this video out:

I watched this earlier today and I think he breaks down the effects of casting very well!

Disclaimer: This link is not associated with Unreal Engine, Epic Games, or their partners.

I’m using Gameplaytagsassetinterface. It’s a very simple C++ implementation. This allows you to add gameplay tags to your pick up actors that will be used as identifiers. Using the C++ implementation allows you to get those tags without having to cast to the specific actor.

image

Once I have the tags I pass them to a function that narrows down the Type of actor. The return provides the Type… (Door, Vehicle, Pickup item, etc). I can then use a switch statement in my interaction logic to call the correct Interface Event.

image

I also make great use of data tables. Using the gameplay tag I can look up the child tag in the table to get specific data.

e.g. WorldItem.Weapon.AK47

  • WorldItem = lootable world asset
  • Weapon type… it’s a gun.
  • AK47 specifically

Weapons data table, row name ak47

I have some experience trying to do this for a beat em up like game so maybe I can throw you a bone. While I am still experimenting ways to do this, probably the easiest way I have seen to do this it to just make a bp actor. Add a static mesh for your weapon or item. Add a box collision and shape it so it is rectangular and when the play walks over it will overlap.

Right click the box collision and add an on begin overlap node. You can narrow its search down with adding component and actor tags. Further refine the boolean looking certain keys to be pressed. So if your player character is overlapping the box collision AND they are pressing a certain key = do something.

That while simple and a quick fix, does not seem to work near as snappy as say using the event tick inside that item’s bp, and then doing an is overlapping component check between that box collision and that players capsule. At which case you will first need to get a ref with a cast or a get actor of class off of event begin play, promote it to a variable, name it something clever, that is your character ref. Drag in your box collision to the event graph of the item. Drag in your character ref and plug them both to is overlapping components (there is like 3 of these, it is the one that allows two component inputs not two actors or an actor and a component) plug that into a branch and print string to test your lap.

But I am still learning many things on this engine and may find a better way to do it down the road.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.