Local Multiplayer Selection Screen Solution!

Merry Christmas folks! I’m creating this in the hopes that it will help myself and others, and even more hoping it works xD:

Go easy on me, I just got it even apparently working, and I’m sure it’ll stand improvement.

It’s a Unity project, 2020.1.16f1 for now and I’ll upgrade as it goes, latest Input System (1.1 prev. 2). Hopefully meta files and such won’t be an issue, I used the Git Unity asset, but I’m not sure if that automatically uses a good .gitignore…ANYWAY…

The purpose:

Everyone, myself more than most, has bleeped and moaned about the difficulties of using the new input system with local multiplayer. Everyone is absolutely right. While it’s easy to add a PlayerInput to something, carrying that from scene to scene and not using the same prefab for every player & persisting devices, is not so much. So full disclosure, I don’t think this will solve everyone’s problems, I am after this specific one, such that you could plug in whatever derelict gamepads you have and jam something with friends. There’s an action map set up in there that I used for a couple controllers I tried out, but of course, this can easily be changed to your heart’s content. Hopefully it would apply to most.

The project:

This is simply a selection screen that will listen for input from Gamepads or Joysticks only. That’s the scope for now. Any button press on such connected devices will spawn a cursor that can be moved with the controller. This is NOT the VirtualMouse that the sample has, I couldn’t get that to work w/ PlayerInput (in fact, that is listed in its TODO comments). I’m basically cheating and working with gameobjects instead of mouse pointers, etc…because that hurts my head.

Press the submit button (typical one, again, adjustable in the action map), and if you’re over one of the selectable player objects (it’s a raycast, so don’t put it 80 miles away), it will freeze there. Pressing start after all existing players (cursors) will go to the gameplay test scene where you can simply move the object (put whatever prefabs/player objects and gameplay you want from there, I imagine).

It’s done in screen space because that way, the idea is you use the actual prefab that would be spawned in your scene, and it’s not a pinprick you can’t even see.

The cursors that spawn have the PlayerInput component. This establishes players with the new system. The selectable objects do as well, but it is disabled. This is because when instantiating in the real scene, they have to have the component, but if we have it activated in the selection screen, they will count as players, and we just want the cursors to define that up front. I’ve finally managed to persist all that through the scene change…or at least I hope I have :P. Hope it helps :slight_smile:

7 Likes

Seems like this still works :p.
So, I’ve added a YouTube video to actually go through the project a bit:

2 Likes