How to know WHAT WEAPON the player picked up?

This is for a beat em up style game. The weapons will be things like bats, knives, bottles, trash cans, barrels, rocks, etc etc.

I followed this tutorial from Matt Aspland - How To Pick Up And Drop Items | Hold Items In Hand - Unreal Engine Tutorial - YouTube

He more less said that this one blueprint for items could be used for all the items, but he never really explained that aspect. I used it to make the character pick up and hold a bat, and also drop the bat when attacked.

But I need to know how to check which item he has and then I guess use a switch on string (or a bunch of booleans) to redirect punch flow to account for the different animations and such.

Any help is appreciated thanks!

It’s blueprint inheritance.

You have one blueprint, which can just contain a static mesh ( unset ), and a enumerator ( type of pickup ).

Then you make a child of that BP, set the mesh to trash can lid, and set the enum to ‘trashcan’. Etc…

Scatter these all over your level.

When the player picks up, they can tell immediately, from a switch on the enum, what kind of thing they have, and act accordingly.

2 Likes

Ok I watched that video and also this video on enumeration.

Its like in ways I understand it and in ways not. I get that you will have weapon class, and then under that will be the children - weaponbat,weaponknife,weaponrock, etc etc…

So I will explain what I have done so far and you can tell me how far off I am lol.

Ok I first created a blueprint - enumeration and named it “E_Weapons”

Opened it up and added a few enumeration names for weapons that might be used.

Now the actor BP I had made for the bat (BP_Item), has like three things, the scene root, the static mesh, and a box collision. I cleared the static mesh like you said.

I then right clicked on the bp and chose create child blueprint. And named it “BP_Item_Baseballbat”. Adjusted the static mesh back to a baseball bat mesh I was using. Now I’m assuming that creating these child blueprints, the main thing will be resizing / scaling the box collision to fit each item? I suppose then the only other things would be setting the static mesh, and add a tag to the MESH, whereas the default scene root has the tag “canpickup”, I think I will just make the mesh the root…

And I just discovered that child bp’s can not be reordered. So I will remake the bat child bp (after I moved the mesh to the root) just for this simpler structure.

Over in my third person character bp. I created an Enum variable and set it to the enum I just created.

And here is the logic for picking up and dropping weapons.

Picking up.

I first check if the TPC’s capsule is overlapping the “bp_item”. The reason I chose the capsule is because I have many box collisions in the TPC bp, and it was picking up weapons like 7 feet away lol, so this narrowed it down a bit. Then out of that for each loop I check if the actor has a tag “pickupitems”. And that feeds a branch. Now after this I have a question mark. Because I imagine we need to check for which weapon it is and thus set the enum variable. But not quite sure how to do this.

I see how you can set the enum for what weapon etc etc.
Image11

And then you could use a switch on enum to execute various code based on what weapon.

Which over in my punch logic, I am checking to see if they have a weapon, and if so go to the weapon branch.

Which I imagine will ultimately look something like this.

And here is drop weapon - its simple but just places the item a set distance from the player when attacked. I would like to have it show the item flung through the air to that spot, and not just appear but that is for later…

Right now, it seems I have to find a way to properly set those enums. What do you suggest here? Thanks!

Here is what I found out. I added two custom events called “What Weapon Though” 1 and 2.

And that goes here, where I set up some branches, and at least with the bat that seems to somewhat be working.

Important to note for anyone out there trying to do this. I found that back in that first image. Where I first marked on the left, that can be set to the Parent “BP_Items” bp, but I found the individual items like the bat, I had to add the “baseballbat” tag to the root or it would not work there in the second pic. I thought for the Parent/Child it would have worked on the static mesh box collision tag but it did not for me.

But it would seem I have another problem now, the bat once attached (held by the player) is drifting what appears to be Y+ very slowly until it is painfully obvious, as shown in this video.

I also would like to make when it first attaches the item, the item would only appear once the players hand is coming away from the ground.

I could not get the knife to be picked up yet. And I notice a bump up effect like the player can walk on it but it should not be able to as all collisions are set to overlap and no to player can step on.

Very good so far. Well done :smiley:

Put the enum in the weapon blueprint, then it’s ready for you on pickup.

Then you don’t need tags as well as enums.

I don’t think you need tags at all actually. I mean if you overlap something and it’s a weapon, you can pick it up, right?

The attachment socket can also be in the main blueprint. When you customise and add the mesh, you can set the orientation of the mesh with respect to the socket, so it’s always in the player’s hand.

Not sure about that drifting, is it attached correctly?

1 Like

Thx, yeah I think it is attached right but will watch a few tuts about attaching. It is using a custom socket that is more in the grip part of the hand and not just the wrist. But for testing purposes might just use a socket that is already there and see if it drifts.

When you say put the enum in the weapon blueprint, would I need to check when it is attached to the player? And do you need to somehow unset an enum like when weapon is dropped?

Yeah, if overlap and you choose you can pickup certain bps.

So far I have tried many attach nodes, and many settings, and that drifting problem is persistent.

Above, you had a switch on enum, to choose the correct pickup anim. You can get the enum from the blueprint on pickup, and immediately know which anim to play.

The drifting I have no idea about, I’m afriad…

1 Like

Enums are nice but it could gets cumbersome when there’s A LOT of them. Depending on what punch flow is - why not store that information inside the weapon itself. Then there’s nothing to compare or switch. When attacking, we use the punch flow that’s inside the weapon actor.

1 Like

That is an interesting idea, hopefully I can figure out how to do it haha.

Ok, will make a thread about that problem. I have not even found anyone else with such a problem yet.