I had a problem with the splitscreen, but i fixed it. If you have a splitscreen but both sides show the same camera and you have implemented the scripts from this video, make sure to uncheck the player layers in the culling mask of your player camera.
Thank you for the video, I was having such a hard time finding information for my cinemachine virtual cameras, it helps a lot as I kept finding people talking about unity's warning that the player input manager isn't compatible with cinemachine.
had problems with 1 controller controlling both characters, rewrote my input code using your Connection Controls section and it worked perfectly. thank you kind man
Funny, I figured all this out myself about 4 weeks ago. Wish I had have watched this first I probably would have a had a much easier time. I still learnt a bit wachting this though. Thanks a bunch!
Bro Your videos are so high quality. It Helped me a lot (I am making a multiplayer game on my channel currently It is on hold but I will get to it soon)
4:15 When the manager is set to "Join player when button is pressed" it will only join a player on a new device. So you cant have 2 players on a keyboard, even if they use a diferent control scheme. When it is set to "join when join action triggered" does that also suffer from the same problem? I asumed yes, for now I am just instantiating the players manualy, because i couldnt get it to work
This. I want to use the new input system since you really can't beat how robust it is and supports so many different controller options, but some of the ways it's implemented that supposedly make it easier (and I'm sure it does in certain scenarios) make it very difficult when it comes to things like character selection, controller connect and disconnect, limiting input to just one controller per game object (if you don't spawn in with prefab, which you wouldn't do if you have a character select screen).
Is there a better way to do this without strings? Before I was using the C# generated class .IPlayerActions interface and in OnEnable() creating a new InputActionAsset based on the C# class created then calling SetCallbacks.
Fantastic video. What would be a clean solution for the following problem: Both players should always be visible but NEVER use splitsceen. The cinemachine camera schould not zoom out indefinitely but to a maximum amount (otherwise players would be too small esp. in a 2D pixelart game). Now you had to move the second player near the next player without him colliding to something.
I’m not sure what you mean when you are moving the second player, but cinemachine has functionality to keep multiple objects in the camera view. That would be where I would start.
@@sanctanox Ah okay. Not sure what to say with the teleporting. Finding the location to teleport to really depends on a lot of things - genre, 3D or 2D, general scene setup, etc. But I'd start with something simple - raycast some random spots along a line between the players and check if they'd work. If they do move the character. If that "works" slowly make it more sophisticated until you get what you you want.
there is a way to start the game with the player instantiated before some control input? and please make the character selection tutorial, wisdom is never too much
Thank you so much for the video! The solution is not the easiest one to work with since it's using strings vs the traditional way of access the C# script directly and finding what we're looking for, but unfortunately, it doesn't work for the multiplayer... I was wondering if there's an explanation for why creating a new instance of the C# script of the actions doesn't work (I saw it commented out at 6:08) In my case, it makes both players share the input of the controller for some reason EDIT: After doing more research on the matter, I found a way that seems to be doing what I wanted; using the C# script generated by the controls and still be able to control both players individually. using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Users; public class PlayerInputHandler : MonoBehaviour { private PlayerInputActions _playerInput; [SerializeField] private PlayerInput _input; private InputUser _user; private void Awake() { _user = InputUser.PerformPairingWithDevice(_input.devices[0]); _playerInput = new PlayerInputActions(); _user.AssociateActionsWithUser(_playerInput); _playerInput.Enable(); _playerInput.Lobby.Return.performed += Disconnect; } public void Disconnect(InputAction.CallbackContext ctx) { _user.UnpairDevice(_input.devices[0]); _playerInput.Dispose(); Destroy(gameObject); } Apparently, associating the current user which is determine by the device that is retrieved from the PlayerInput with the new instance of the C# controls seems to lock the C# controls to that player only.
Hmm. I think it depends on exactly what you need to produce. Short answer: Use the tool that you are the most comfortable with. I'm not sure Unity is 100% ready for producing motion graphics, but I've definitely thought about it myself. You could have issues with frame rate and making sure that animation take a particular number of frames... Whereas with something like aftereffect you have much more control.
Just asking how would you do the script part for the onEnable and onDisable, but for a car? this is what i have for it. I'm not to sure what i'm doing private void OnEnable() { player.FindAction("HandBrake"); move = player.FindAction("Acceleration"); move = player.FindAction("SteeringAngle"); player.Enable(); } private void OnDisable() { player.FindAction("HandBrake"); player.Disable(); }
I know this is a few months already, but I'm desperately looking for a way to make a character selection screen for split-screen local multiplayer. There doesn't seem to be any tutorial about it. The new input system nicely deals with easy split screen, but that's only for ad-hoc joining of players. I want to tie players to controllers and selectable characters throughout multiple scenes. The documentation on Unity is very spotty on this. Help!
This is kind of a big topic and it's been a while since I made the video, but what I'd look to do is create a separate game object that the player is connected to - in the video this was the character itself, but for your case it might just be a gameObject with a few scripts attached. I would mark that object as "Do not destroy on load." That should allow you to carry this player connected object between scenes. You could demo/test this functionality by following the video, marking each character as "Do not destroy on load" and attempting to load a new scene. If that works there's still a lot of work to connect everything, but maybe its a good start?
@@OneWheelStudio Thank you so much for your reply. I spent many hours working off of this idea, but I did make one tweak to simplify the concept slightly. So at its core, the important thing is that in your lobby, you configure the join behaviour to be "join when button pressed". This can load any prefab, as long as it has a PlayerInput. So like you said, I just made a dummy object that represents the player. The important part is that you keep track of the devices that are paired to users, and what the order is in which users join. This order can be used later to keep consistent split-screen corners. Then after the lobby, what I did was switch the join behaviour to manual. I destroyed all the dummy player models, and put the character player model on the PlayerInputManager as the main prefab. Then I load the next scene. And finally, I joined each player manually in their original order and with their registered paired devices, with the correct character prefab. This actually works reasonably well. In my case, rejoining the game manually was easier than switching the character gameobject. Glad I pulled this off though! Thanks!
Hello Jeremy! Loved the tutorial! I did have quick question about Gizmos and Icons in split screen. Whenever I use OnDrawGizmos or even setting an icon through the inspector, those images skew between both cameras. Not the biggest deal, but makes it a headache for debugging. Have you come across this problem?
@OneWheelStudio What if I want cinemachine to follow an individual player but still see both players on both split screen subsections. Great video btw! I do feel like cinemachine is sorely lacking in the idea above however. Anyone?
I'm not sure I 100% follow on what you want, but Cinemachine does have the ability to multiple targets and keep them in the frame. Also it sounds like maybe you'll need mutliple camera each with their own behavior assigned.
@@OneWheelStudio I followed the tutorial. The problem is that the cameras cull all but the player they follow. It's still desirable to see those players when they are in frame right? But follow their individual target
Does the controller connect correctly? Can you see the controller in the UI debugger? In my experience sometimes a restart of Unity and or the computer is necessary at first to get everything talking to each other.
@@OneWheelStudio So I decided to just restart everything in a new unity project and it worked. The only thing that is not working is the camera does not rotate around my player with the mouse and the right stick
I would assume this would work on most platforms, you might have to do some testing and or check out the documentation. As for the Xbox menu popping up, I'm not an xbox user myself, not entirely sure what that would mean, but I would assume if it's an xbox specific window you would need additional code for that.
I'm running into a problem when I try to find actions using strings. The action maps and the actions are being found, but they are not responsive. I debug the action.phase and they are constantly in "Waiting" state and it looks like it wont receive any input from any of my devices (keyboard and gamepad). Do you have any idea how I could solve this?
I'd try the UI Debugger just to double check all is working as expected. Beyond that... Hmm. This is a new one for me. Did you enable the actions or action maps?
@@OneWheelStudio I did enabled the action map and also tried enabling the action itself, also the fact the action.phase says "waiting" shows the actions have been enabled. The input debugger shows the inputs are being received because the values are changing. One more strange thing is the player input manager is not spawning any player on button press, even when I'm correctly assigning the prefab with a player input component (neither on button press or on a defined trigger action from the action map).
@@OneWheelStudio Ok, I've created a new Input action asset and now is working. The difference is now I didn't create any control schemes while for the old one I had one for Keyboard one for Gamepad. Although just having no control schemes works, I understand they might be important for local multiplayer set up, so I'd like to get it working eventually in case you have an advice. I read this on some post: "When control schemes are present, PlayerInput will entirely rely on the requirements on those control schemes to decide what to pair. It could be the case where the setup can lead to joining not resulting in the respective device getting paired at all and neither PlayerInput nor PlayerInputManager detecting the mismatch." Hope this helps to anyone having the same issue in the future. Also thanks a lot for your videos and tutorials, the format is really nice and clear.
Hmm. Okay. Strange. Only other two things I can think about is if you didn’t switch the project over to use the new input system (in the project settings) or are you on a really new Version of unity?
I had the same problem. And yes, I am using the latest version. For me it worked the same way as @icarosh1. Curiously, after I deleted the schema of the old input action asset and moved the "Join" action over the "Movement" action and regenerated the C# script, the old input action asset now also worked. Unfortunately, I can no longer recreate the bug. By the way, restarting the engine or the PC did not work.
You should be able to edit the code and spawn players with any method (triggers, events, whatever). I think the example is using player input just because that's common.
Yep. If you're new to the input system definitely check out my earlier video. There's a poop ton going on. Link: ruclips.net/video/YHC-6I_LSos/видео.html
inputAsset = this.GetComponent().actions; Getting an error on this line. Assets\Scripts\PlayerController.cs(19,22): error CS0029: Cannot implicitly convert type 'UnityEngine.InputSystem.InputActionAsset' to 'InputActionAsset' Which makes no sense to me but I figured I'd ask to see if there was a solution to anyone who comes across this video. Perhaps I am using the wrong Unity version because no one else seems to have this issue.
HI! Your videos help me a lot , and I'm found somthing want to share,so I have two device;keyboard and Gamepade,I consult your video and tried to made player could control object,but two device will all can control object(it should just one device can control),look for Solution and found that inputsystem have "ControlScheme",and can use //GetComponent().SwitchCurrentControlScheme(Keyboard.current); use this code and in your video Connection Controls part ,it can lock device and change it hope it help!
Tutorial Blog Post: onewheelstudio.com/blog/2022/2/3/split-screen-multi-player-with-unitys-new-input-system
Tutorial Code: github.com/onewheelstudio/Adventures-in-C-Sharp/tree/main/Split%20Screen
I had a problem with the splitscreen, but i fixed it. If you have a splitscreen but both sides show the same camera and you have implemented the scripts from this video, make sure to uncheck the player layers in the culling mask of your player camera.
already uncheck the layers but still show the same camera :( can u help me
@@sarahpuspdew on the prefab select Player1 only, the script will handle the rest of the added player for the cinemachine works
By far one of the clearest and easiest tutorials for this complicated ass input system.
Thanks
Clear, concise and no (or very little) BS is what we go for around here ;) Glad it was useful.
he litraly glosed over the entier step of the control scemes
Thanks for the helpful tutorial! Character selection screen tutorial would be very nice to have too as you mentioned.
Thank you for the video, I was having such a hard time finding information for my cinemachine virtual cameras, it helps a lot as I kept finding people talking about unity's warning that the player input manager isn't compatible with cinemachine.
had problems with 1 controller controlling both characters, rewrote my input code using your Connection Controls section and it worked perfectly. thank you kind man
Glad it was useful!
Same issue lol
I can't believe Unity didn't fix this still
Funny, I figured all this out myself about 4 weeks ago. Wish I had have watched this first I probably would have a had a much easier time. I still learnt a bit wachting this though. Thanks a bunch!
Bro Your videos are so high quality. It Helped me a lot (I am making a multiplayer game on my channel currently It is on hold but I will get to it soon)
I'm still very confused but this did solve my controller moving both players issue so thanks
Yeah I've been having the same issue
I've got my 2 ps controllers hooked up and only one works I'm still figuring it out
Thank you for the video, i'm doing a local multiplayer using the new input system and i was having trouble using CineMachine with it.
4:15 When the manager is set to "Join player when button is pressed" it will only join a player on a new device. So you cant have 2 players on a keyboard, even if they use a diferent control scheme.
When it is set to "join when join action triggered" does that also suffer from the same problem? I asumed yes, for now I am just instantiating the players manualy, because i couldnt get it to work
Is it too late to tell you i'm interested in a player selectin screen ??
This. I want to use the new input system since you really can't beat how robust it is and supports so many different controller options, but some of the ways it's implemented that supposedly make it easier (and I'm sure it does in certain scenarios) make it very difficult when it comes to things like character selection, controller connect and disconnect, limiting input to just one controller per game object (if you don't spawn in with prefab, which you wouldn't do if you have a character select screen).
Is there a better way to do this without strings? Before I was using the C# generated class .IPlayerActions interface and in OnEnable() creating a new InputActionAsset based on the C# class created then calling SetCallbacks.
My question as well. The string method doesn't feel clean...
Have you figured it out?
I am still not able to have individual cameras even after replacing the InputHandler with the new script in my player prefab.
Very good!
Fantastic video. What would be a clean solution for the following problem: Both players should always be visible but NEVER use splitsceen. The cinemachine camera schould not zoom out indefinitely but to a maximum amount (otherwise players would be too small esp. in a 2D pixelart game). Now you had to move the second player near the next player without him colliding to something.
I’m not sure what you mean when you are moving the second player, but cinemachine has functionality to keep multiple objects in the camera view. That would be where I would start.
@@OneWheelStudio what I meant is: If the distance from player one to player two is too big. Player two should be teleported to player one.
@@sanctanox Ah okay. Not sure what to say with the teleporting. Finding the location to teleport to really depends on a lot of things - genre, 3D or 2D, general scene setup, etc. But I'd start with something simple - raycast some random spots along a line between the players and check if they'd work. If they do move the character. If that "works" slowly make it more sophisticated until you get what you you want.
there is a way to start the game with the player instantiated before some control input? and please make the character selection tutorial, wisdom is never too much
amazing video, your great
Thank you so much for the video!
The solution is not the easiest one to work with since it's using strings vs the traditional way of access the C# script directly and finding what we're looking for, but unfortunately, it doesn't work for the multiplayer...
I was wondering if there's an explanation for why creating a new instance of the C# script of the actions doesn't work (I saw it commented out at 6:08)
In my case, it makes both players share the input of the controller for some reason
EDIT:
After doing more research on the matter, I found a way that seems to be doing what I wanted; using the C# script generated by the controls and still be able to control both players individually.
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Users;
public class PlayerInputHandler : MonoBehaviour
{
private PlayerInputActions _playerInput;
[SerializeField] private PlayerInput _input;
private InputUser _user;
private void Awake()
{
_user = InputUser.PerformPairingWithDevice(_input.devices[0]);
_playerInput = new PlayerInputActions();
_user.AssociateActionsWithUser(_playerInput);
_playerInput.Enable();
_playerInput.Lobby.Return.performed += Disconnect;
}
public void Disconnect(InputAction.CallbackContext ctx)
{
_user.UnpairDevice(_input.devices[0]);
_playerInput.Dispose();
Destroy(gameObject);
}
Apparently, associating the current user which is determine by the device that is retrieved from the PlayerInput with the new instance of the C# controls seems to lock the C# controls to that player only.
Awesome video
thx bud very helpfull
Hello~
Has there been any guides on doing this via a player select screen?
I haven’t created one 😔
what are your thoughts on using cinemachine for making motion graphics and how is it compared to aftereffects and unreal
Hmm. I think it depends on exactly what you need to produce. Short answer: Use the tool that you are the most comfortable with.
I'm not sure Unity is 100% ready for producing motion graphics, but I've definitely thought about it myself. You could have issues with frame rate and making sure that animation take a particular number of frames... Whereas with something like aftereffect you have much more control.
Thank you for this!
Just asking how would you do the script part for the onEnable and onDisable, but for a car?
this is what i have for it. I'm not to sure what i'm doing
private void OnEnable()
{
player.FindAction("HandBrake");
move = player.FindAction("Acceleration");
move = player.FindAction("SteeringAngle");
player.Enable();
}
private void OnDisable()
{
player.FindAction("HandBrake");
player.Disable();
}
I know this is a few months already, but I'm desperately looking for a way to make a character selection screen for split-screen local multiplayer. There doesn't seem to be any tutorial about it. The new input system nicely deals with easy split screen, but that's only for ad-hoc joining of players. I want to tie players to controllers and selectable characters throughout multiple scenes. The documentation on Unity is very spotty on this. Help!
This is kind of a big topic and it's been a while since I made the video, but what I'd look to do is create a separate game object that the player is connected to - in the video this was the character itself, but for your case it might just be a gameObject with a few scripts attached. I would mark that object as "Do not destroy on load." That should allow you to carry this player connected object between scenes. You could demo/test this functionality by following the video, marking each character as "Do not destroy on load" and attempting to load a new scene. If that works there's still a lot of work to connect everything, but maybe its a good start?
@@OneWheelStudio Thank you so much for your reply. I spent many hours working off of this idea, but I did make one tweak to simplify the concept slightly. So at its core, the important thing is that in your lobby, you configure the join behaviour to be "join when button pressed". This can load any prefab, as long as it has a PlayerInput. So like you said, I just made a dummy object that represents the player. The important part is that you keep track of the devices that are paired to users, and what the order is in which users join. This order can be used later to keep consistent split-screen corners.
Then after the lobby, what I did was switch the join behaviour to manual. I destroyed all the dummy player models, and put the character player model on the PlayerInputManager as the main prefab. Then I load the next scene. And finally, I joined each player manually in their original order and with their registered paired devices, with the correct character prefab.
This actually works reasonably well. In my case, rejoining the game manually was easier than switching the character gameobject. Glad I pulled this off though!
Thanks!
@@Tovi7 hi do you have link to your code? i would like to implement a character selection too but dont know how
Does anyone know why can't I add the Input Action? Have been trying to start but for some reason the Input Action option does not appear to me
It doesn't appear in your code? Did you maybe forget to generate the C# code?
I know this is off topic for the video but I have to ask, are you the guy who does the Odin Inspector voice overs?
Nevermind, I watched the third person video and you mentioned the odin videos :D I knew I wasn't crazy. Keep up the great content :)
Hello Jeremy! Loved the tutorial! I did have quick question about Gizmos and Icons in split screen. Whenever I use OnDrawGizmos or even setting an icon through the inspector, those images skew between both cameras. Not the biggest deal, but makes it a headache for debugging. Have you come across this problem?
Sorry I haven't run into that at all - I've never made great use of gizmos.
Ah, no worries! Thanks for the response!
@OneWheelStudio
What if I want cinemachine to follow an individual player but still see both players on both split screen subsections. Great video btw! I do feel like cinemachine is sorely lacking in the idea above however. Anyone?
I'm not sure I 100% follow on what you want, but Cinemachine does have the ability to multiple targets and keep them in the frame. Also it sounds like maybe you'll need mutliple camera each with their own behavior assigned.
@@OneWheelStudio I followed the tutorial. The problem is that the cameras cull all but the player they follow. It's still desirable to see those players when they are in frame right? But follow their individual target
I am running into a problem when I try to join with my controller nothing happens and the jumping does not work. Could you help me?
Does the controller connect correctly? Can you see the controller in the UI debugger? In my experience sometimes a restart of Unity and or the computer is necessary at first to get everything talking to each other.
@@OneWheelStudio So I decided to just restart everything in a new unity project and it worked. The only thing that is not working is the camera does not rotate around my player with the mouse and the right stick
Does this work for xbox? Like would the player selection xbox menu pop up when you add a player?
I would assume this would work on most platforms, you might have to do some testing and or check out the documentation. As for the Xbox menu popping up, I'm not an xbox user myself, not entirely sure what that would mean, but I would assume if it's an xbox specific window you would need additional code for that.
so this is the next brackeys channel
I can dream... ;)
I'm running into a problem when I try to find actions using strings. The action maps and the actions are being found, but they are not responsive. I debug the action.phase and they are constantly in "Waiting" state and it looks like it wont receive any input from any of my devices (keyboard and gamepad). Do you have any idea how I could solve this?
I'd try the UI Debugger just to double check all is working as expected.
Beyond that... Hmm. This is a new one for me. Did you enable the actions or action maps?
@@OneWheelStudio I did enabled the action map and also tried enabling the action itself, also the fact the action.phase says "waiting" shows the actions have been enabled. The input debugger shows the inputs are being received because the values are changing. One more strange thing is the player input manager is not spawning any player on button press, even when I'm correctly assigning the prefab with a player input component (neither on button press or on a defined trigger action from the action map).
@@OneWheelStudio Ok, I've created a new Input action asset and now is working. The difference is now I didn't create any control schemes while for the old one I had one for Keyboard one for Gamepad. Although just having no control schemes works, I understand they might be important for local multiplayer set up, so I'd like to get it working eventually in case you have an advice. I read this on some post:
"When control schemes are present, PlayerInput will entirely rely on the requirements on those control schemes to decide what to pair. It could be the case where the setup can lead to joining not resulting in the respective device getting paired at all and neither PlayerInput nor PlayerInputManager detecting the mismatch."
Hope this helps to anyone having the same issue in the future. Also thanks a lot for your videos and tutorials, the format is really nice and clear.
Hmm. Okay. Strange. Only other two things I can think about is if you didn’t switch the project over to use the new input system (in the project settings) or are you on a really new Version of unity?
I had the same problem. And yes, I am using the latest version. For me it worked the same way as @icarosh1. Curiously, after I deleted the schema of the old input action asset and moved the "Join" action over the "Movement" action and regenerated the C# script, the old input action asset now also worked. Unfortunately, I can no longer recreate the bug. By the way, restarting the engine or the PC did not work.
For me it says on the line "move = player.FindAction("Move");" the Object reference not set to an instance of an object
Argh why does Unity force us to use input systems to spawn characters? I think it really limits me in implementing my ideas in my way.
You should be able to edit the code and spawn players with any method (triggers, events, whatever). I think the example is using player input just because that's common.
I finally found the input system in the package manager there’s something called registry you have to go to start process
Yep. If you're new to the input system definitely check out my earlier video. There's a poop ton going on. Link: ruclips.net/video/YHC-6I_LSos/видео.html
@@OneWheelStudio do you know how to setup tree painter under terrain tools
@@harryrithman1977 Off the top of my head, I don't know. You may need to add some tree models to make it work.
@@OneWheelStudio did that already is there something else I have to do
I honestly don't know. I haven't used the terrain tools in a very long time. Sorry.
noice
the this.getcomponent().actions; doesnt work for me? the ".actions" doesnt register
same
inputAsset = this.GetComponent().actions;
Getting an error on this line.
Assets\Scripts\PlayerController.cs(19,22): error CS0029: Cannot implicitly convert type 'UnityEngine.InputSystem.InputActionAsset' to 'InputActionAsset'
Which makes no sense to me but I figured I'd ask to see if there was a solution to anyone who comes across this video. Perhaps I am using the wrong Unity version because no one else seems to have this issue.
nvm fixed it with some magic.
private UnityEngine.InputSystem.InputActionAsset inputAsset;
HI! Your videos help me a lot , and I'm found somthing want to share,so I have two device;keyboard and Gamepade,I consult your video and tried to made player could control object,but two device will all can control object(it should just one device can control),look for Solution and found that inputsystem have "ControlScheme",and can use
//GetComponent().SwitchCurrentControlScheme(Keyboard.current);
use this code and in your video Connection Controls part ,it can lock device and change it
hope it help!