Gamepads, Local Multiplayer, Dynamic respawning

Hey guys,

So I have a few questions here. I’ll give a brief explanation of what I’m trying to accomplish so there is some context, even if this specific instance doesn’t get solved, I’d like some thought process on what the best way would be to achieve what I’m looking for.

Its a local multiplayer game (all players on 1 PC) using 4 Gamepads (xbox 360). Each player has a character that can sprint, jump, and use a unique ability. The players will be basically running an obstacle course as a race, and use their abilities anyway they can to get to the end. I have my character setup and running, I built all of my functionality in myCharacter and then I use a “playerNum” variable to give each player slot their specific ability. (I’ll post screenshots for all of this as well.)

At one point I wanted to make all my functionality in myCharacter and then make copies based on it and hook up the stuff I needed for that “character” but with the overrideable functions and what not I couldn’t quite figure out how to get it to work.

I’m trying to spawn characters at the game start, 1 for each gamepad, in the future I’d like to let the player pick their character on another screen, and then spawn them all with their selected characters, but for now I’m just trying to get the spawning working properly with fixed characters in each gamepad slot. Heres how I am getting a second player in game currently.

This is working, technically. Gamepad 1 controls the defaultPawn that is spawned from a player start. Gamepad 2 controls the spawned and possesed pawn in the screenshot, I can’t test anymore gamepads, but I’m assuming they will work. This is coming off of BeginPlay event in my Level blueprint currently. I wanted to move it to my gameMode construction script, but couldn’t access the spawning nodes, maybe I should make a function out of it? My problem with the current setup, is I get a 3rd pawn spawned, that just floats in air (assuming its unpossessed and chilling). But I’m not sure why it spawns in general? I only have 1 player start, for the defaultPawn to spawn at automatically. The second player is spawning currently at a specific location.

Heres a quick reference to how I’m handling the unique abilites based on “playerNum” and the movement of each possesed pawn.

My final question is about killing, respawning and possessing the new pawn. I will manually place spawn/checkpoints throughout the map. I’ll also place a volume at the bottom of the map and if players fall into it they should die and respawn at the closest spawn point. (I know I could use killZ, but the maps are kind of dynamic in the Z direction and it might take a long time to fall to the lowest killZ.) My Current setup looks like this.

I’ve commented it to help explain what I -think- I am doing. However it is failing at the cast to myCharacter.

Here is the findNearestSpawn function.

Sorry if thats a lot of text but I wanted to be thorough so that you have all the info you might need to help me figure this out. Either the direct issue or hints at how I could implement this stuff in better places (gameMode? Construction scripts, playerController, etc etc)

Thank you!

Hi Esquire,

Are you on a dedicated server?

No,

I’m just using the play button, no extra clients, and no dedicated server, the game would just be running on one PC with 4 xbox gamepads hooked in.

Thanks.

I was going to try that initially, I suppose I can try to copy some functionality into the new pawns, and cut it out of the master pawn. I know in theory it should just inherit it all and work, but I couldn’t get overridiable functions to be useable in the child and I couldn’t right click to say implement function.

Is there anyway to get control of what that first pawn that spawns is? I know its my default pawn, but when I tried to disable a default pawn and spawn my own, I wasn’t able to get control of both pawns with each controller. But if I set it to default and setup my 2nd pawn like I have now. I get proper control over player 1 and player 2, BUT I get that 3rd pawn, that just floats and is unpossessed.

Final question. Where should I place this spawning logic? GameMode? Level Blueprint?

Thank you!

Well I have one suggestion for sure for you for now, I can try to look more into this at a later time, however. For now, you are on the right track when it comes to the players. You want to set a master pawn and then create children blueprints - one for each player you will have. Then you can set up 4 separate spawn points and have each one summon an individual child pawn, preventing you from trying to summon them all on one point. Hopefully this points you in the right direction!

I would definitely push it into the level blueprint to make sure it is set as you want it per level. Have you posted your questions to the forums as well? There are many users who have a lot of good information in the blueprint scripting section! You can find them at http://forums.unrealengine.com.

Did you find the solution to the third pawn?
How did you get the PlayerNum in spawn actors from class?

To get my PlayerNum variable to appear in spawn actor from class, go to your blueprint you will be spawning, select the variable and check the Expose on Spawn button.

As for getting rid of the mystery pawn, I believe it ended up being an error on my part. I ended up just spawning an actor and possessing it with the next available player slot. I did that in a loop, that iterrated as many times as I had players (so 2, 3 or 4 times.) In the end, each player slot.

I think the loop went something like Loop Body > Create Player (-1) > Spawn actor of class (PlayerNum = Index of loop) > Possess Pawn (the spawned actor from before) > End.

So it creates a player at the next available slot, spawns a pawn with the playerNum variable exposed, and that is set by the iteration of the loop, so if its the 2nd time, thats player 2’s pawn, if its 3rd time, its player 3 etc etc. and then I posses it with that player slot/controller.

In my pawn setup i basically had the A button go through a Switch on Int. The playerNum was the int. So if player 2 pressed their button, it went down the 2 chain and did some special ability only player 2 should have, etc etc.

Hope that helps.