More help needed with character-swapping system

Hello again, I was wondering if anyone could help me out again on the character-swapping system I’ve been working on for my game.

How the character-swapping system works is that the four cardinal directions of a gamepad’s right analog stick each corresponds to a different character that will be spawned when the stick is pushed in the corresponding direction i.e. if the Up direction on the gamepad’s right analog stick corresponds to Character B then Character A will be replaced by Character B when the stick is pushed upwards.

So far I managed to get the above to work but with one issue, and that’s my game actually has five playable characters not four. Basically, the problem is that right now I can switch from Character A to Characters B, C, D & E, and characters B-E can freely switch between one another but none of them can switch back to Character A.

The idea I had in mind to address issue is that when the player switches from Character A to Character B, if the player then pushes the same button that summoned Character B, it will then switch back to Character A. would also apply to Characters C-E with the button that summoned each of the corresponding characters then switching to back to Character A when pressed again. In theory anyways, but in practice I’m not really sure on how to actually go about implementing idea.

Anyways, I hope I’m making sense with all of and that somebody could help me out with the problem I’m currently experiencing. As always, any help whatsoever would be greatly appreciated!

Since I haven’t gotten any responses to my question so far, I thought a visual aid would help people to understand what I’m trying to do.

So to reiterate, I’m trying to make a system of swapping out one character for another, with a total of five different characters to switch between.

The player switches between each character through use of a game controller’s right analog stick, with each cardinal direction switching to a different character i.e. if the player pushes the analog stick to the left, then Character A will swapped out with Character B, while pushing stick to the right will switch to Character B, etc.

I’ve managed to get the character-swapping system working mostly as intended except for one issue. The problem is that when you switch from Character A (who is the main protagonist of the game) to another character, there’s currently no way to switch back to Character A/the main character as there are five characters but only four directions on the analog stick.

What I would like to do is that when one switches from Character A to another character, pushing the analog stick in the same direction would instead of switching to the character just swapped in again would switch back to Character A.

So for example, when you switch from Character A to Character B by pushing the right analog stick to the left, if you pushed it to the left again it would switch back to Character A instead of trying to swap Character B in again.

would also apply if you were to switch from say Character B to Character D by pushing the analog stick upward. If pushed the analog stick up again after switching to Character D from B, it would switch back to Character A.

I hope helps clarify things a bit and that somebody can help me out in implementing idea into my current character-swapping system.

Hello there. First of all, just to clarify, Character A is the “main” character and whenever the player is controlling a different character, say character B, then pushing the right analog stick in the same direction as the currently controlled character, then it will always switch back to character A. Please correct me if I’m wrong here.

Now, if that is the case. Then you can solve your issue by simply adding a boolean to show if a character is currently being used. If the character is being used and the player inputs to switch to that character, then you switch to character A instead.

From the screenshot of the blueprint showing the InputActionSwitchTo function, I would say the easiest solution would be to add 4 boolean variables to your blueprint. One for each character that is not A. Having that, you can add a “Branch” node in the method (maybe following the already existing branch) that would check if the character is being used. The flow of the function would be something like:

InputActionSwitchToCharacterB → Branch(IsFalling) → Branch(IsCharacterBInactive) → DestroyCurrent → SpawnNew → PossessNew

Let me know if solves your issue or if you understood what I meant.

Also, if you plan on adding more characters to your game you may want to consider a different system for character switching. Maybe having them in an array and using the right analog stick to travel the array right and left and confirming the selection with a separate input. Just a suggestion since I know nothing of the actual game you are building. Good luck!

1 Like

maybe will help you :face_in_clouds:


the select and the spawn put it inside a function and call it every time you press in a direction, so you don’t repeat the code so many times

1 Like

Alright, following 's advice I finally managed to get the character-swapping system as intended.

I’m not sure if the implementation was done in the most efficient manner, I feel like it should be simplified to get rid of redundant code, but at least it works.

Blockquote
Also, if you plan on adding more characters to your game you may want to consider a different system for character switching.

Yeah, I have no absolutely no plans to add any more characters, five is the absolute max I’m willing to go with. I’ve outlined the entire game for the most part in regards to story, levels & gameplay mechanics so any additional playable characters would require me to basically throw out my entire outline in order to restructure the gameplay & story around the addition of any new characters.

Additionally, the reason I wanted to use the right analog stick to switching characters was to preserve the flow of the gameplay. The problem with using a menu to switch between characters is that the gameplay would have to come to a complete stop while the player navigated the menu. Whereas, I felt using the analog stick allowed the player to quickly switch between characters without stopping the game. Originally, I was going to use the D-pad instead but decided against it after reading online that many people prefer to use the D-pad in side-scrolling platformer games instead of a analog stick.

Thanks for the response! Although I’ve already gotten a solution, your suggestion of using Enumeration might help me out in the future on something else I have in my mind for my game.

1 Like