Local Multiplayer and Split-Screen - New Input and Cinemachine

Поділитися
Вставка
  • Опубліковано 4 жов 2024

КОМЕНТАРІ • 82

  • @OneWheelStudio
    @OneWheelStudio  2 роки тому +2

    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

  • @SubatomicPlanets
    @SubatomicPlanets 2 роки тому +14

    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.

    • @sarahpuspdew
      @sarahpuspdew Рік тому

      already uncheck the layers but still show the same camera :( can u help me

    • @ronaldsalvador9342
      @ronaldsalvador9342 6 місяців тому

      @@sarahpuspdew on the prefab select Player1 only, the script will handle the rest of the added player for the cinemachine works

  • @bagabhoul
    @bagabhoul 2 роки тому +7

    By far one of the clearest and easiest tutorials for this complicated ass input system.
    Thanks

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому +3

      Clear, concise and no (or very little) BS is what we go for around here ;) Glad it was useful.

    • @PatrickK-er6yu
      @PatrickK-er6yu 5 місяців тому

      he litraly glosed over the entier step of the control scemes

  • @greglhoffmann
    @greglhoffmann Рік тому +4

    Thanks for the helpful tutorial! Character selection screen tutorial would be very nice to have too as you mentioned.

  • @camo_man
    @camo_man Рік тому +2

    I'm still very confused but this did solve my controller moving both players issue so thanks

  • @RobotFrog12
    @RobotFrog12 2 роки тому +1

    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

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому +1

      Glad it was useful!

    • @timurradman3999
      @timurradman3999 7 місяців тому

      Same issue lol
      I can't believe Unity didn't fix this still

  • @JackNoble5
    @JackNoble5 2 роки тому +3

    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.

  • @Betruet
    @Betruet 2 роки тому

    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!

  • @umapessoa6051
    @umapessoa6051 2 роки тому +1

    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.

  • @SojoTaku
    @SojoTaku 2 роки тому +1

    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)

  • @Morituri96
    @Morituri96 Місяць тому +1

    thx bud very helpfull

  • @halivudestevez2
    @halivudestevez2 2 роки тому +1

    Very good!

  • @CamrunThomas
    @CamrunThomas Рік тому +1

    amazing video, your great

  • @coobbyo
    @coobbyo 2 роки тому

    Thank you for this!

  • @MarekNijaki
    @MarekNijaki 2 роки тому +1

    Awesome video

  • @sanctanox
    @sanctanox Рік тому +1

    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.

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      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
      @sanctanox Рік тому

      @@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.

    • @OneWheelStudio
      @OneWheelStudio  Рік тому +1

      @@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.

  • @joelabraham6287
    @joelabraham6287 2 роки тому

    so this is the next brackeys channel

  • @timurradman3999
    @timurradman3999 7 місяців тому

    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.

  • @Matteizera
    @Matteizera Рік тому

    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

  • @Nyclia_Mycandra
    @Nyclia_Mycandra 4 місяці тому

    Hello~

  • @profzeco
    @profzeco Рік тому

    I am still not able to have individual cameras even after replacing the InputHandler with the new script in my player prefab.

  • @Jalechah
    @Jalechah 2 роки тому +3

    Is it too late to tell you i'm interested in a player selectin screen ??

    • @Distortion3933
      @Distortion3933 2 роки тому

      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).

  • @TheSixoul
    @TheSixoul Рік тому +1

    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.

    • @timurradman3999
      @timurradman3999 7 місяців тому

      My question as well. The string method doesn't feel clean...
      Have you figured it out?

  • @evilmurlock
    @evilmurlock Рік тому

    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

  • @Wobling
    @Wobling 2 роки тому

    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?

    • @Wobling
      @Wobling 2 роки тому

      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 :)

  • @patrickfye7699
    @patrickfye7699 2 роки тому

    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
      @OneWheelStudio  2 роки тому

      Sorry I haven't run into that at all - I've never made great use of gizmos.

    • @patrickfye7699
      @patrickfye7699 2 роки тому

      Ah, no worries! Thanks for the response!

  • @fastsolution
    @fastsolution 2 роки тому

    what are your thoughts on using cinemachine for making motion graphics and how is it compared to aftereffects and unreal

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      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.

  • @sheenadrysdale8176
    @sheenadrysdale8176 Рік тому

    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();
    }

  • @TheSixoul
    @TheSixoul 2 роки тому

    Has there been any guides on doing this via a player select screen?

  • @harryrithman1977
    @harryrithman1977 2 роки тому

    I finally found the input system in the package manager there’s something called registry you have to go to start process

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      Yep. If you're new to the input system definitely check out my earlier video. There's a poop ton going on. Link: ua-cam.com/video/YHC-6I_LSos/v-deo.html

    • @harryrithman1977
      @harryrithman1977 2 роки тому

      @@OneWheelStudio do you know how to setup tree painter under terrain tools

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      @@harryrithman1977 Off the top of my head, I don't know. You may need to add some tree models to make it work.

    • @harryrithman1977
      @harryrithman1977 2 роки тому

      @@OneWheelStudio did that already is there something else I have to do

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      I honestly don't know. I haven't used the terrain tools in a very long time. Sorry.

  • @jossieftheguitarist4677
    @jossieftheguitarist4677 2 роки тому

    noice

  • @maripellecer
    @maripellecer 2 роки тому

    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

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      It doesn't appear in your code? Did you maybe forget to generate the C# code?

  • @Haunchfluff
    @Haunchfluff Рік тому

    @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?

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      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.

    • @Haunchfluff
      @Haunchfluff Рік тому

      @@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

  • @Tovi7
    @Tovi7 Рік тому

    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!

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      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?

    • @Tovi7
      @Tovi7 Рік тому +2

      @@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!

    • @sarahpuspdew
      @sarahpuspdew Рік тому

      @@Tovi7 hi do you have link to your code? i would like to implement a character selection too but dont know how

  • @noahordway31
    @noahordway31 2 роки тому

    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?

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      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.

    • @noahordway31
      @noahordway31 2 роки тому

      @@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

  • @jasithiss
    @jasithiss Рік тому

    Does this work for xbox? Like would the player selection xbox menu pop up when you add a player?

    • @OneWheelStudio
      @OneWheelStudio  Рік тому

      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.

  • @duncanwang7163
    @duncanwang7163 2 роки тому +1

    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!

  • @icarosh1
    @icarosh1 2 роки тому

    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?

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      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?

    • @icarosh1
      @icarosh1 2 роки тому

      @@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).

    • @icarosh1
      @icarosh1 2 роки тому

      ​@@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.

    • @OneWheelStudio
      @OneWheelStudio  2 роки тому

      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?

    • @inf8th
      @inf8th 3 місяці тому

      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.

  • @kilabeann
    @kilabeann Рік тому

    For me it says on the line "move = player.FindAction("Move");" the Object reference not set to an instance of an object

  • @jessyjdirado
    @jessyjdirado 4 місяці тому

    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.

    • @jessyjdirado
      @jessyjdirado 4 місяці тому

      nvm fixed it with some magic.
      private UnityEngine.InputSystem.InputActionAsset inputAsset;

  • @tOhB_
    @tOhB_ Рік тому +1

    the this.getcomponent().actions; doesnt work for me? the ".actions" doesnt register