Download

Switching between Pawns in Top Down Game on mouse event

Hi everyone,
I’m trying to create a Top Down Game in which I have a stationary camera looking down on the playing field and several pawns. The player should be able to select/switch pawns. I am able to Possess any desired pawn through keyboard events using the level blueprint. This is rather impractical as I will have about 15-25 pawns in the game.
I have found many tutorials online that describe how to switch between characters, all of those describe it from a 1st person perspective using the 1st person character BP to accomplish this. I have not been able to adopt this into my BPs.
My ideal case scenario would be to possess just by moving the mouse over the pawn, less ideal but still interested if anybody has suggestions would be to click on the pawn or select via UMG. Clicking on the pawn is less desirable as I am drawing the path of my pawn out and the click event is likely mess up the drawing event.

I hope this makes sense and that somebody has some ideas on how to approach this. Any hints, tips, links or any other kind of help is appreciated.

Hello Ad Oculos,

I’m far from pro, and my method is maybe not the best optimized way…but maybe try this ? I’ve tested it really fast and seems to work !

Added in the Level BP

Thanks, just tried it, works great.

You’re welcome :slight_smile:

Classic case of I posted after just a quick test and the devil seems to be in the details.
Switching pawns works great with the above method, however it seems to break the ability to draw the path for the pawns. I’ve been trying to solve it but just can’t figure it out. Everything works fine until the cursor moves over one of the pawns, at that moment drawing the path out stops working.

Hello Ad Oculos,

I’m not sure to understand at 100%, but anyway can you please send more details ? Take a screenshot of your pawns BP for exemple.

Thank you

Krystoh,

Thanks so much for the offer to help, I have been able to figure out what the problem was.

My pawn has a spline at the root, I’m “drawing” out a line in the viewport by detecting the location of the mouse click, adding spline points and then adding a spline mesh component to make that line visible. The object representing the player is spawned at begin play and then follows that line. This player happens to be another Pawn BP. So when I begin play, my spline pawn is not visible but the player is. So possessing when mousing over worked only that it didn’t possess the correct pawn. I have now added an object to my spline pawn and set it to be hidden in game and this works to possess the correct pawn.
Thank you so much for your help, I really appreciate it.

If you are still interested in how I set this up I can post some screenshots.

Hello Ad Oculos,

You’re welcome, it’s normal ! Moreover i’ve received many help here so i want to help people also when i can. :slight_smile:

Thank you a lot for your detailed explanation ! It’s really kind of you but please don’t bother yourself with screeshots, i’ve understand your technics now and i find your explenation really usefull to me too !!

Good luck in your project :slight_smile: