No announcement yet.

Cycling inventory in the proper order, whether i have three or fifteen of the items

  • Filter
  • Time
  • Show
Clear All
new posts

    Cycling inventory in the proper order, whether i have three or fifteen of the items

    Might be a bit of a strange title, but hopefully gets the point across. Basically I have several weapon pickups spread around a map. I am working on a quick switch function which actually works right now if i have every weapon - the weapons cycle in a predictable order with each tap of the button; I cycle through all the pistols first, then all the smgs to all the ar’s, a rocket launcher, and so on.

    However I want this order preserved if i have say three weapons instead of all of them. For example, if i go pick up the knife, the rocket launcher, and an AR, when i tap to switch from unarmed i want to go knife > AR > launcher

    I’m storing the weapons in an enum array and switching on enum to get the current version working, but if i’m missing any weapons i have to tap through some “blanks” until i hit an array index i actually have. Anyway hope this makes sense. Thanks in advance for any advice, it is greatly appreciated!
    Last edited by kgkraeer; 06-23-2019, 10:32 PM.

    Actually thanks anyway, I was overthinking it. I wrote a function that runs through branches in the proper order every time the button is tapped, checking to see which weapons are held, and whichever ones turn out to be “true”, that weapon gets equipped.


      I use an integer array to loop this...

      Originally posted by MostHost LA View Post
      To streamline the event graph you should probably create custom events for each weapon firing mechanism and feed it off / reposition it wherever else.
      Usually that already cleans up the noodle mess significantly.

      Another way to keep order - just in general - is local variables. within functions particularly.

      Yet another way to sort or handle things is Functions.

      As far as I go, since I'm sort of coding something that is a close cousin to an FPS, I have my system set up with an array and a loop so that weapons can be cycled though. Like a standard FPS going from 0 to 9. The number in the array actually matches up the same offset of the keys on the keyboard... because why would anyone want to finagle with the array if you can just make it match?
      here's a sample.
      Click image for larger version

Name:	weaponcycling.png
Views:	37
Size:	175.2 KB
ID:	1632794
      Obviously the montage to play should be changed depending on the weapon, where it comes from where it's attached etc. This is just a basic prototype and not what the final system would end up looking like if you are already dealing with sockets (I'm not for the moment still prototyping the right animations for movement).

      Anyway, back to your actual question.

      You have LMB, RMB, and MWD (mouse wheel down) as possible buttons.

      You can drag off from any of inputs and immediately hand off to a custom function.
      The function within the character blueprint will then handle all the logic of checking what is going on and how it should respond to the button press in it's own event graph page without much mess on the main blueprint.
      It would sort of be like passing it of to the weapon blueprint - but it doesn't have any lag or necessary checking other than adding one function to the stack.. Since unreal is still OOP it obviously handles the classic stack/function call system quite well.

      Hope that helps. If it's not enough or you want a different alternative that also allows more options, you could create a custom event and move it down like explained here:

      I'm not sure how you would or if you could instantiate or call the event inside the weapon to keep the code with the weapon itself without some issues on slower systems, but if you are really set on doing it here you can find out how to call the events you set up from the character blueprint (and yes, somehow you still have to call them from the character bp).

      Best of luck

      Last edited by MostHost LA; 06-23-2019, 11:37 PM.