You.
Welcome back and this video, we're going to talk a little bit about being able to tell which of our
weapons is the one that's equipped and how we can actually swap weapons out and make sure that that
information is being stored properly.
So let's take care of a few things.
So let's go back to item that CBP now an item that CBP, we have set item properties and this is called
in our set item state function.
Let's go back and look at set item state and you'll see that we set the state.
That's our anum.
And then we set item properties and set item properties.
We go ahead and switch on the item state that we're setting and then we set the properties for the components
in our item.
And we have states for pickup equipped, falling equipment chirping and we have not yet implemented
the state for picked up, which is when we pick it up.
But we're not equipping that item.
It's just going into our inventory.
So we can go ahead and add that case here.
And this is going to be case, item state.
And we're going to choose picked up.
And we'll take a break down here.
Now, this is going to be very similar to equip and tarping because we want to set the pickup, which
it visibility to force.
We want to set the items, simulate physics to false, enable gravity to false.
We're going to set the visibility to false as well.
But we also want collision response to all channels to ignore collision enabled to no collision and
the same thing for the area sphere in collision box.
So this is almost exactly what we want.
We're going to go ahead and copy that and put it into the picked up state.
And the only thing we're going to change is the item mesh set.
Visibility is also going to be false.
So essentially this weapon will exist, but we won't really know that it exists because we won't see
anything and it won't interact with anything.
So that's for the picked up state.
Now, when do we set it to the picked up state?
Well, let's go into shooter character that Seip.
And here we have our get pickup item where we're casting to the weapon and we're checking to see if
the inventory is not full.
And then we're adding the weapon to the inventory.
And at this point, we need to set the item state here.
So we're going to say weapon set items, state e item state picked up.
And now we shouldn't be able to see that item.
Now what happens in swap weapon?
Let's go ahead and take a look at that function here we see we got drop weapon and drop weapon.
If we peek the definition of that, that takes care of setting the item state to the falling state.
So that takes care of the properties for that.
And then we equip the weapon, which is the weapon to swap and equip weapon.
If we pick the definition for that, we handle setting the item state to equipped for that one.
Now, when we have a weapon equipped, the icon should be elevated slightly so we can see that that's
the weapon that we have equipped.
Now we should have a slot index variable in our item class so we know which index in the inventory we're
in.
So here an item that age.
Let's go ahead and add a integer variable.
So it's going to be in 32 and this is going to be a slot index.
Now we need a new property and this is going to be visible anywhere since this should be set from code.
It'll be a blueprint read only.
And we'll use the category and meta specifiers for the above variable M0 item and for the comment will
say slot in the inventory array.
Now we're going to create a.
Getter and setter for this, and these are both going to be public, so we're going to come down here
to our getters and setters, I'm going to say force in line and in thirty two for the Geter, it'll
be called get Slote index will be CONSED and it'll return Slote Index.
We're also going to add a force in line setar that's going to be void and it's going to be called Set
Slote Index which will take in 32 called index and we'll simply set slot index equal to index.
So your basic getters and setters here.
Now the default weapon will automatically get a slot index of zero and we're going to do that in our
Shoura character that SEPI where we go to begin play and we can see that we're calling Sporn default
weapon.
We're adding it to the inventory.
It's going to be the first element in the inventory array.
So we're going to say equipt weapon.
Set Slote index, and we're going to set it to zero, and for the variable itself, we can give it a
default value.
An item that keeps constructor will stick this up here and say Slote index.
We'll just give it a default value of zero.
Now, once we add a weapon to the inventory, we need to set it Slote Index.
So let's go to shoot the character that SEPI and go back to our get pickup item function.
And as soon as we add this to the inventory, we need to set the slot index here.
Now, before we add it, we can say weapon.
Set Slote Index.
And we can simply set it to the size of the inventory.
So we're going to say inventory numb now when an item is in the inventory, it will have the slot index
stored next.
When we equip an item, we want the inventory bar widget to receive some information.
So now we're setting the slot index when we add a weapon to the inventory.
So let's go ahead and conclude the video here.
And in the next video, we're going to work on sending a message to the inventory bar widget whenever
we're adding an item to the inventory.
And that way the inventory bar widget will know so that it can react and do things like animate icons
and make them look elevated and things like that.
We'll handle that in the next video.