Local Multiplayer with NEW Input System - Unity Tutorial

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

КОМЕНТАРІ • 232

  • @samyam
    @samyam  3 роки тому +39

    For those who want split-keyboard play:
    -Make 2 control schemes of type Keyboard on your InputActionAsset.
    -Assign the different keys to the corresponding control schemes (e.g. WASD and Arrow Keys)
    -Now, you can either manually spawn the two players using their respective control schemes:
    var p1 = PlayerInput.Instantiate(playerPrefab,
    controlScheme: "KeyboardLeft", device: Keyboard.current);
    var p2 = PlayerInput.Instantiate(playerPrefab,
    controlScheme: "KeyboardRight", device: Keyboard.current);
    forum.unity.com/threads/2-players-on-same-input-device.763949/
    docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.PlayerInput.html
    -Or once the first or second player has joined (you can subscribe to the Player Joined event),
    switch the control scheme on the player with SwitchCurrentControlScheme(…)
    docs.unity3d.com/Packages/com.unity.inputsystem@1.0/api/UnityEngine.InputSystem.PlayerInput.html#UnityEngine_InputSystem_PlayerInput_SwitchCurrentControlScheme_System_String_UnityEngine_InputSystem_InputDevice___
    -Make sure to disable the auto switch component on the Player Input so it doesn’t switch between different devices/control schemes.

    • @HoodedOlive
      @HoodedOlive 3 роки тому

      When I try to put the name of the player prefab I use in place of the name in there (playerPrefab) unity just spits out a compiler error saying that it doesn't know what the player name is doing there. So is there something else that that playerPrefab represents?

    • @samyam
      @samyam  3 роки тому

      The player prefab in this example is the same one fed into the Player Input component as I showed in the video, it is just a representation of the player with it’s camera and optional UI. You probably need a reference to your prefab in the script for it to work properly.

    • @StevieVu
      @StevieVu 3 роки тому

      So for the subscribe to the Player Joined Event.
      Do I create a public void SwitchPlayer() method which then uses the playerInput.SwitchCurrentControlScheme("Controller", Keyboard.current); ?
      I was hoping for an example in the documentation and a little confused on how to implement this.

    • @samyam
      @samyam  3 роки тому

      @@StevieVu You can press Behaviour>Invoke Unity Events>In your script make a function like so
      public void OnPlayerJoined(PlayerInput playerInput) {
      // your code here
      }
      and in the behaviors section of the player input component drag your script and select the function you made (this is one of the ways, you can also use SendMessages although I don’t recommend that approach)

    • @HoodedOlive
      @HoodedOlive 3 роки тому

      Ok so now whenever I try and do this it says that device is not an overload of instantiate. So then what's wrong because I just copied and pasted the code above and switched it out with my varibles in some places. So I don't really know how to fix this.

  • @zukipmnow4445
    @zukipmnow4445 3 місяці тому +1

    This is the only tutorial that worked for me. I've been trying to make a multiplayer game for a long time now but I never understood the new input system. Great tutorial!

  • @rumblebox_
    @rumblebox_ 3 роки тому +16

    These are easily some of the best Unity tutorials on UA-cam. Great video!

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

    Man. You never fail to give exactly what Im looking for. Thank you so much for these videos

  • @zapposh
    @zapposh 3 роки тому +9

    Wonderful, I was secretly hoping you would make a video one day on exactly THIS! Thank you :-)

    • @samyam
      @samyam  3 роки тому +1

      Nice! 😄

  • @ColdOneK
    @ColdOneK 3 роки тому +1

    Helpful vid.
    Two things...
    1: KEYBOARD BASS HYPE!!!!
    2: If you add inputs while in a control scheme, it'll automatically tick that control scheme's checkbox. Weird way to say it, but you probably get what I mean ; ]

    • @samyam
      @samyam  3 роки тому

      Thank you!!

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

    This was fantastic, thank you very much for this. It solved a few problems for me, somewhere along the way my old control scheme was tangled up and it was controlling 2 characters at once, and for the life of me I couldnt figure out where it was coming from. Following this tutorially helped immensely with my issue so thanks again

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

    Dope tutorial. Been messing with new input system about 3 years ago and it was such a mess back then. Had to create my own library for handling all of the devices connecting and reconnecting, there was no documentation and the one exisitng was thrash. But here with 15 mins tutorial I can get it all working like a charm. Finally Unity made a closure to this system and it can be easily used.

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

      Yes it’s been a long time coming, thanks for watching!

  • @bhavya.prashant
    @bhavya.prashant 3 роки тому +3

    Woah! What a timing! Just what I was looking for. Brilliant tutorial.

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

    That was a very good tutorial, you got to the point and didn't waste my time, well done.

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

    Best Unity tutorials on YT. Thank you so much for this!

  • @neenaw
    @neenaw 3 роки тому +3

    Excellent as always 🙏🏾

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

    I am using a fps controller but when i add two players both of them move.

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

    It's a magic! Thank you so much! I love you samyam, you are the best!

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

    Thanks Samyam! Really appreciate this video :)

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

    Thank you very much! Very useful tutorial!

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

    Thanks that was exactly what i needed

  • @javierIglesias-b3q
    @javierIglesias-b3q 2 роки тому +4

    This tutorial has saved me! I was scared I'd have to watch 30 minutes of someone explaining how to code multiplayer in a near-silent voice. Thanks!
    I have one question; so far, I've watched up to 9:25, why is nothing coming up when I click on the function button but "MonoScript"? Do you have any idea why?

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

      Have you found the solution?

    • @javierIglesias-b3q
      @javierIglesias-b3q Рік тому

      @@marmadon6341 I found it but finished the game and don't have the code.

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

    Dynamic "CallbackContext" doesnt show for me (9:26) Im on 2021.3.22 .
    Ive gone back and forth over this, but its not showing. anyone else come across this, or know why? My OnJump and OnMove are public voids too.

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

    Could you please do a video on how to do local multiplayer with existing objects? For example, I have two teams and I want a player to be able to control each team.

  • @incrediblegaming0910
    @incrediblegaming0910 5 місяців тому +1

    does anyone know why in the player controller function why onMove and onJump dont show up? (im doing this in 2D mode btw)

  • @Bravehearte
    @Bravehearte 3 роки тому +1

    Nice tutorial, thanks for sharing.

    • @samyam
      @samyam  3 роки тому +1

      Yes good point, I made a new video recently explaining the differences between the different action types and upon further investigation Value is preferable for most situations :)

  • @sirpugstudios
    @sirpugstudios 6 місяців тому +1

    anyone know how to fix: Assets\scripts\PlayerController.cs(14,13): error CS0246: The type or namespace name 'vector2' could not be found (are you missing a using directive or an assembly reference?)

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

    Thank you.

  • @songwonchoi1679
    @songwonchoi1679 2 роки тому +6

    Hi, thanks for the amazing tutorial. However, I have issues with my gamepad input and keyboard input mixing up with eachother. My movement is functioning as it should, but anything else such as shooting/crouching/jumping inputs are applied on both of the players whenever I start using gamepad. Thanks for the help

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

    Very good tutorial. Thank you so much :)

  • @snell9444
    @snell9444 3 роки тому

    Love your Tutorials :)

  • @Fitrox
    @Fitrox 3 роки тому

    On point and up to date. Great tutorial.

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

      how is this up to date my friend?
      how can you use this tutorial to set up 2 controllers with the same input?

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

    Thanks! This was really useful!

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

    Great video, thank you!

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

    I have 2 gamepads (XBox) and 2 characters, but they both move at the same time. How do I prevent this?

  • @disorderlygage1184
    @disorderlygage1184 3 роки тому +1

    This is the only tutourial i found that actually worked and it was the most simple one lol. I do have a question tho. I'm striving to make a local co-op fps game and it looks a bit weird when everyone has the same character model. How do I set up specific players to spawn in. Ex- player one is a cube, player 2 is a sphere, player three is an octopus, and player 4 is a snake. Those aren't my models btw just trying to make myself clear lmao

    • @samyam
      @samyam  3 роки тому

      Check my pinned comment! You can manually instantiate players with different prefabs as needed :)

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

    THANKK YOUUU

  • @abdulkadirdursun6072
    @abdulkadirdursun6072 3 роки тому

    Great video. Thanks a lot :D

  • @TearyHumor
    @TearyHumor 3 роки тому

    Awesome video and really well explained! Instant sub from me :)

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

    Ok I followed the tutorial but my keyboard and controller inputs have become combined. I have no idea how to fix it

  • @chickencow1598
    @chickencow1598 5 місяців тому +1

    is this possible with 2 controllers

  • @jean-michel.houbre
    @jean-michel.houbre 3 роки тому

    You have a new subscriber!

    • @samyam
      @samyam  3 роки тому

      Thank you!

  • @MBM_first
    @MBM_first 3 роки тому

    thx for this vid it helped me a lot :)

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

    thanks for the the awesome tutoril

  • @xuiubot
    @xuiubot 3 роки тому

    Best tutorial on the new input system i've watched, it helped me a lot

  • @Me-ji7uq
    @Me-ji7uq Рік тому +1

    Can you add two controllers? If yes then how?

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

    How could I get the position data from the spawned players?

  • @pourmydrank
    @pourmydrank 3 роки тому

    your fingers are machines!!

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

    Is there a way to assign device to player that is ALREADY in the scene ?

  • @ilyasyildiz6091
    @ilyasyildiz6091 3 роки тому +1

    Good Job

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

    Would this kind of approach work for A VR setup on Android running quest/pico headset?

  • @raaghavthapliyal2713
    @raaghavthapliyal2713 3 роки тому +1

    i am also doing this in 2d

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

    What do I need to change if I want two different game characters?

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

    Hello! I followed this tutorial and it was great. What I want to know is how to start my game with the 2 characters already spawned in and able to be controlled. I was trying to make a script that would simply press spacebar and the 'A' button once when the scene loads, but that proved to be too difficult. Thank you!

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

      Did you ever find that out? I'm looking for something simliar

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

      @@johnsummers101 Can't remember exactly, but I'd assume as long as each has their own camera and unique input system that it would work

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

      @@walbobo I want them to share the same camera. Its kinda like a half court basketball game. Where you pick one or two players. They spawn at the same time. They have the same controls, but use their own gamepad. But as I type this out, I think you mean Player1 will get Player1 controls, then player2 will be assigned player 2 controls. That still leaves it pretty ambiguous as either controller can be picked up by either player controller

  • @bossfakealeks12345
    @bossfakealeks12345 3 роки тому +3

    If possible can there be a part 2

    • @samyam
      @samyam  3 роки тому +1

      What kind of content would you be looking to see in a part 2?

    • @bossfakealeks12345
      @bossfakealeks12345 3 роки тому

      samyam maybe a 2d local multiplayer Game ,if you can 😊

    • @samyam
      @samyam  3 роки тому +3

      Gotcha, I'll take it into account for a possible future video!

    • @bossfakealeks12345
      @bossfakealeks12345 3 роки тому +1

      samyam thx

    • @raaghavthapliyal2713
      @raaghavthapliyal2713 3 роки тому

      @@bossfakealeks12345 that would be good

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

    I am 99% sure that I will not get an answer but my problem is that no functions are appearing in player events except monoscript
    Am I missing something?

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

      When you add a PlayerController script in events, drag it from the inspector tab, not from the project

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

    I made this in unity 2d and The player goes through objects with collider 2ds, how could I change this? Great tutorial by the way.

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

    Hi! This is great solution and all works fine, but i have a possibly dumb question. I decided to go a little further and set spawn points for each player, and here I am a little confused due to the number of fields and options in the player input manager. As I understand it, it is necessary to create the necessary empty objects on the stage for the spawn points themselves, but where and how is the player’s spawn function called and how can I set the spawn point? Should i use manual join behavior? How to setup Player Join Events correctly? May be there is a simple solution but there is so many questions in my head right now)))

  • @0DDoomUs0
    @0DDoomUs0 Рік тому

    Awesome tutorial!
    How are players removed / split screen put back to non-split? I want players to join, die, go away, and join anew, like old arcade games where the second player can stop playing for a while and then hit start to come back in. But it looks like PlayerInputManager has no way to manually invoke or force a player to leave.

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

    What about 2 controllers?

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

      That's what I'm here to find out, but I think I have it figured out. 🤔 I'll post a video about it if I get it 👍

  • @P_tricc
    @P_tricc 3 роки тому +3

    Great tutorial, could you make a tutorial on swipe detection with the new input system?

    • @samyam
      @samyam  3 роки тому +1

      I'll put it on my list!

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

    Hello, I wonder how to use 2 joysticks to control different players, is that supported in vanilla unity?

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

    Great tutorial, Simple and easy to understand but I have a glitch that when a controller disconnects and then reconnects it creates a new instance of the player and doesn’t reconnect to the old player is there anyway to fix this or is it something completely different

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

    Great tutorial! But is there a way to get the cube to not be floating off the ground?
    EDIT: figured out the answer if anyone else has the same issue, chagne the skin width on the "Character Controller" component to 0

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

    Would this still work if I used 2 game padd

  • @Unshackled.Dreamer
    @Unshackled.Dreamer 3 роки тому

    Hey, if you are ok with answering on an old video (lol) I have a question. So is there a difference in this between 3d and 2d games? I am making a local multiplayer smash bros type game except with guns. It's very rudimentary as of now. I have the controls working on my gamepad and it runs smoothly, the problem comes in when I try to go multiplayer. Currently when I spawn a player in I have no input. So for example I built my input and controls, turned the player into a prefab, deleted player from scene, and added the prefab to the player manager, and now controls don't work anymore. I even used debug statements and the actions arnt being called for some reason. Note: I am using two controllers as I plan to have up to 8 players. If you respond I will love you forever lol
    Edit: I subbed btw. This is the best input system tutorial out there rn!

    • @samyam
      @samyam  3 роки тому

      I try to respond to all the comments 🙂 The concept should work regardless of 2D or 3D mode. What control schemes are you using for both players? Make sure the actions are being enabled. You can use the Input Debugger to see if your actions are enabled and what values they are getting ua-cam.com/video/ICh1ZEaVUjc/v-deo.html
      We also have a Discord channel where you can ask in the help channel with more detail discord.gg/Eu9462Jq

  • @shendtytynxhiu8075
    @shendtytynxhiu8075 3 роки тому +1

    Great Tutorial! I have one question though, how do I achieve the same effect with one keyboard? I made to schemes with different inputs however when I press the button to join the player only one will join.

    • @samyam
      @samyam  3 роки тому

      Thanks! I haven't done this personally, but this forum might help you out:
      forum.unity.com/threads/multiple-players-on-keyboard-new-input-system.725834/
      Which seems they create a virtual keyboard for the second player
      Virtual device: "This allows you to create your own Devices, which can be useful for testing purposes, or for creating virtual Input Devices which synthesize input from other events."
      docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Devices.html

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

      Hi, I managed to go around that by programming my own Input Manager, since the unity one supports only 1 player for one device, thus mutiplayer on one kayboard is a bit tricky. I created this little script:
      public GameObject playerPrefab1;
      public GameObject playerPrefab2;
      PlayerInput p1;
      PlayerInput p2;
      void Start()
      {
      p1 = PlayerInput.Instantiate(playerPrefab1, controlScheme: "Player1", pairWithDevice: Keyboard.current);
      p2 = PlayerInput.Instantiate(playerPrefab2, controlScheme: "Player2", pairWithDevice: Keyboard.current);
      }
      This will create two players at the beginning with the specified schemes on the same keyboard. Hope this helps!

    • @samyam
      @samyam  3 роки тому +1

      Thanks!

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

    I have a question: does make sense to add a different Player Input Manager for each player?

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

    Just wondering, is there any way to modify the follow camera so it uses a anchor for the camera rotation like in a camera orbit script? Currently the scripts conflict with another since the CameraFollow uses the player transform as a target, and I want to be able to use the split screen look with a rotating camera for each player. Thank you again for your help on my original comment!

  • @booksforlife7903
    @booksforlife7903 3 роки тому +1

    So I followed you and when I went to move my player, it did nothing. Any help would be awesome. I really want to learn these subjects.

    • @samyam
      @samyam  3 роки тому

      Make sure there aren't any errors in the code (Window>General>Console). Also, make sure your events are properly set in the PlayerInput component and that the functions to read the input are getting read correctly. You can also use the input debugger (ua-cam.com/video/ICh1ZEaVUjc/v-deo.html) to verify that your input actions are getting the input read correctly.

    • @booksforlife7903
      @booksforlife7903 3 роки тому

      @@samyam Thank you, I guess i'm going to just go through your video again. I really appreciate the quick reply also btw so thank you. One more thing is I've learned a couple different ways to use the inputs, would u say this is one of the most effective ways? Thanks a bunch, your new fan.

    • @samyam
      @samyam  3 роки тому

      Thank you 😁 Well up until recently I was Generating a Script from the Input Action Asset and making an instance of that in the code, which is a good way, however since the code is generated, it can’t be changed at runtime (the input action asset) which makes stuff like rebinding keys hard. So I’d recommend using the PlayerInput component and most of the documentation suggests. You can query your actions directly instead of using the events as so
      playerInputActions.actions[“Look”].ReadValue....
      and you can cache the Look action (playerInputActions.actions[“Look”]) to avoid having that long call at the beginning

    • @booksforlife7903
      @booksforlife7903 3 роки тому

      @@samyam So I got It working, then I followed your smooth camera tutorial, nice btw, but now It will let me join in two players with just the keyboard not even having my controller plugged in and my players wont move anymore. Do you have any idea what might be wrong with it? It also says don't destroy on load in the hierarchy and when i click on it the second player joins in, but cant move.

    • @samyam
      @samyam  3 роки тому

      Hmm maybe you removed some sort of setting in the process? It’s hard to tell without seeing the project. You can join our discord and post your steps more in depth in the help channel to see what we can do if you’d like discord.gg/bvQEGk7

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

    goated

  • @LostAngel175
    @LostAngel175 11 місяців тому

    Can i use this in Genarate C# class?

  • @hoomanhoney
    @hoomanhoney 3 роки тому +4

    This is one of the most well explained tutorials I've found! Thank you so much for sharing and teaching.
    I have a question though. I followed all the steps but my keyboard and my controller move both of my characters in sync. Any idea why? I've created two different control schemes

    • @samyam
      @samyam  3 роки тому +3

      Hmm in the player input component did you deselect switch between devices? I found the player input manager to be buggy sometimes

    • @hoomanhoney
      @hoomanhoney 3 роки тому

      ​@@samyam wow thank you for the fast reply! Yeah I took off the auto switch in the inspector for my character's prefab. :( maybe it's just buggy but I thought I'd ask! I'll try it in a fresh project file, maybe that will fix it.

    • @samyam
      @samyam  3 роки тому +1

      Yeah just make sure in the input action to select keyboard or controller for that corresponding action 🙂

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

    Great Video Sam thank you!
    I have some questions though, I hope you don't mind answering to an old video.
    I'm currently working on a local split-screen multiplayer mode for my game and I want to primarily use controllers for gameplay. I have an issue where both characters are controller by one controller. The spawning works on the second controller but I don't have separate control over the other character which is very weird plus the documentation doesn't have a good way of explaining this, do you have any possible suggestions to fix this? Do I have to create a second control scheme for player 2 and bind the same buttons on the controller and manually set the scheme in code? Thanks in advance :)

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

      Hey! Make sure to check the pinned comment on this video I think it will help solve your issue! :)

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

      @@samyam Yeah, it finally works now thank you 🙏

  • @samiduzgun
    @samiduzgun 3 роки тому

    very good

  • @sinlessdragon6514
    @sinlessdragon6514 3 роки тому +1

    Valeu!

  • @icetrooper4875
    @icetrooper4875 3 роки тому

    I was struggling to make one keyboard for many (at least 2 players) players to work, but... there are so many bugs there. PlayerInputManager is missing reference for new players when the second player use the same device (keyboard). There are some hacky solutions with creating Virtual Device Keyboard, but... meh. For now, don't try to use same device for many players with this system. If I'm wrong, comment below.
    Anyway, really good tutorial with keyboard+gamepad setup!

    • @samyam
      @samyam  3 роки тому

      Yeah it’s a bit buggy, I recommend making a new control scheme in the input action asset for each of the players, that was it doesn’t overlap. So make 2 of type Keyboard and Mouse and the first one assign maybe the WASD keys and the other the arrow keys (or whatever controls you are using) I go over making a control scheme here ua-cam.com/video/f0wax8LufqQ/v-deo.html

  • @skymound1463
    @skymound1463 3 роки тому

    Hey Sam, great video once again ! I was wondering what way is the better (offers most of features/best performance) between using the Component "Player Input" or writing directly in script controls.Player.Jump.performed += _ => my_function() ? Thanks a lot

    • @samyam
      @samyam  3 роки тому

      I don’t think you should worry about the performance between the two, but you can always measure it with the profiler if you’d like. The second option you can subscribe to individual events and it’s more clear (.started, .canceled, .performed) while the PlayerInput gives you one event when the action has been triggered. Up to your preference :) I personally like the first option since it’s directly in the code.
      docs.unity3d.com/Packages/com.unity.inputsystem@0.2/api/UnityEngine.InputSystem.Plugins.PlayerInput.PlayerInput.html

    • @skymound1463
      @skymound1463 3 роки тому

      ​@@samyam Thanks a lot for your answer ! I'm gonna try the first option ;) And try to figure out how to do implement the local multiplayer feature with it !

  • @alphaanar2651
    @alphaanar2651 3 роки тому +1

    Yooo you are sooo skilled programmer. Why don't you make a game and publish it on "play store"?
    l believe you will get 10.000.000 downloads.

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

      Thank you! I had published some okay games a couple years ago but I didn't update them and most got taken down. I haven't had time to work much on a game, but I'm planning on it!

  • @AcidMonkie
    @AcidMonkie 3 роки тому

    I have this all working with a Rigidbody2d instead of a Movement Controller. Both characters (keyboard/controller) run & jump, but after running the game once, the PlayerInput component in my Player prefab loses the "Actions: Input Action Asset" reference to PlayerControls. Anyone have an idea why this happens?

    • @samyam
      @samyam  3 роки тому

      Seems to be a bug, what version of the input system are you using (and what Unity version)? Try upgrading the input system version if you can. Should be fixed in version 1.1-preview.3.
      forum.unity.com/threads/playerinput-component-loses-its-reference-to-an-inputactionasset.861118/
      forum.unity.com/threads/input-action-asset-gets-unassigned-from-instantiated-prefab.1004381/

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

    Hi Samyam,
    I can appreciate this was made about a year ago now, do we know if cinemachine supports this yet?

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

      I don’t think it supports it directly yet unfortunately but there is a workaround you can do:
      onewheelstudio.com/blog/2022/2/3/split-screen-multi-player-with-unitys-new-input-system

  • @polyk302
    @polyk302 3 роки тому

    help, when I connect my Xbox controller the player keeps jumping for some reason

    • @samyam
      @samyam  3 роки тому

      Check the Input debugger, Window>Analysis>Input Debugger and see if your gamepad is printing out a value for the jump button, if it’s not you might have set up the input action or script wrong (or there might be a bug with unity’s input manager)

  • @dushes_botalov
    @dushes_botalov 3 роки тому

    Nice 🥴👍

  • @mr.soulless904
    @mr.soulless904 3 роки тому

    I spent whole 2 days making the mechanics of the game and the player... until when i use the player input manager and it doesn’t work for me it just spawns another player but both controllers can control him, sometimes it doesn’t spawn a player just the two controllers moving one character... i give up...😓😪

    • @samyam
      @samyam  3 роки тому

      Make sure you have 2 separate control schemes for the two different players, check my pinned comment for more information.

    • @mr.soulless904
      @mr.soulless904 3 роки тому

      @@samyam thanks samyam you’re the best!

  • @niracaldwell
    @niracaldwell 3 роки тому

    thank you so much! i was able to create a basketball demo for my project i did it in 2D, i am now trying to do a 2d shooting game
    problem is, my play-testers had much confusion on who was who
    how can I change the color of a cube/sprite when they join?

    • @samyam
      @samyam  3 роки тому

      Great! The PlayerInputManager has a onCreatePlayer that you can use to manually spawn the prefab and edit it as necessary
      docs.unity3d.com/Packages/com.unity.inputsystem@0.2/api/UnityEngine.InputSystem.Plugins.PlayerInput.PlayerInputManager.html

    • @samyam
      @samyam  3 роки тому

      Ah you wouldn’t edit the prefab directly, once you make an instance of it via Instantiate then you can get it’s material or renderer component and change the color
      docs.unity3d.com/Manual/InstantiatingPrefabs.html
      answers.unity.com/questions/1524909/renderer-material-color-changing-with-script.html

  • @chiro5533
    @chiro5533 3 роки тому

    Nice video, but its is possible this with two o more players each playing with a gamepad?, do you need will create two o more schema controllers with gamepad?

    • @samyam
      @samyam  3 роки тому +1

      I think it'd be best to create a different schema for each player so the Player Input Manager doesn't get confused.

  • @julianmccann2934
    @julianmccann2934 3 роки тому

    How would i go about doing this but with multiple characters? To specify i am meaning like two different characters in a fighting game have same buttons but different results. How would one do this? My apologies for poor explanation

    • @samyam
      @samyam  3 роки тому

      There are several ways you can possibly do it, what comes to mind is mapping an input action to a certain character attack depending on the character.
      So you can have a generic scriptable object that you can extend and have an instance per character of the fighting game.
      And so for each instance/character, you could swap out the function that it calls (you can more easily do this via an interface, and have a class that implements this interface with its attack type).
      This might help you:
      learn.unity.com/tutorial/create-an-ability-system-with-scriptable-objects#5cf5ecededbc2a36a1bd53b7
      www.radermatthew.com/scriptable-object-practice

    • @julianmccann2934
      @julianmccann2934 3 роки тому

      @@samyam Thanks!

  • @phoenixwafflegames4232
    @phoenixwafflegames4232 3 роки тому

    Question. Why is there the player parent prefab instead of simply the player prefab? Why use the extra step?

    • @samyam
      @samyam  3 роки тому

      So we can also have the camera and UI if needed under the parent, and when the player is instantiated so will their respective camera and UI

    • @phoenixwafflegames4232
      @phoenixwafflegames4232 3 роки тому

      @@samyam Ah. So controlling other components besides just the main character?

    • @samyam
      @samyam  3 роки тому

      The prefab is just a grouping of objects with specific settings already set, we only control one player in the player prefab, but we also want to be including our camera when instantiating the character. However we do not want the camera to be a child of the player directly because that can cause issues with the camera movement, so in this case it’s best to make another parent which has the camera and the player as children. And then that is made into a prefab which we instantiate. Hope that helps.

  • @martyboi4215
    @martyboi4215 3 роки тому

    hey i am very stuck on how to spawn players at certain places and not just to the origin of a prefab. eg. i want2 cars to spawn at two different parking spots in a parking lot....
    if anyone has any ideas pls let me know

    • @samyam
      @samyam  3 роки тому

      You can either manually instantiate the players yourself (in the PlayerInputManager set to manual then you can instantiate with PlayerInput.Instantiate(...) ) and place them in the positions that you'd like, or you can subscribe to the PlayerJoined event from the PlayerInputManager, and that will give you a reference to the PlayerInput component of the player that was just spawned, and you can get the gameobject from that (I believe with .gameObject as usual), and change the position to what you'd like.

  • @ramanpokhrel8355
    @ramanpokhrel8355 3 роки тому

    Can we add 2 or more player using just keyboard
    Like p1: W A S D
    And p2: Arrow keys

    • @samyam
      @samyam  3 роки тому +1

      You can add two different Keyboard control schemes with different keys and each player will correspond to one of the schemes:
      forum.unity.com/threads/local-multiplayer-with-split-keyboard-support.825603/

    • @ramanpokhrel8355
      @ramanpokhrel8355 3 роки тому

      @@samyam i made it in the most inefficient way by creating double player control script(I was desperate) and splitting screen in traditional way. thanks for the link and awesome tutorials :D

  • @Dinii899
    @Dinii899 16 днів тому

    2:30

  • @HarryAlire
    @HarryAlire 3 роки тому

    Hi, I really need some help, I currently have it all working everything is set up like yours except I have the wasd and arrowkeys instead.
    I go to play it and only one of the characters will move!
    The second character just won't move at all,
    If anyone could help me with this, that would be amazing

    • @HarryAlire
      @HarryAlire 3 роки тому

      I forgot to mention that I used different movement code not sure if that might be doing it

    • @samyam
      @samyam  3 роки тому

      Hey! Did you check out my pinned comment on this video? That might help you out with players using the same device (keyboard). Make sure you have two different control schemes and auto switch off in the player input component

    • @HarryAlire
      @HarryAlire 3 роки тому

      ​@@samyam So i Fixed it!
      I saw your comment earlier but it didnt work, then I did some research and replaced
      'device: Keyboard.current'
      with
      'pairWithDevice: Keyboard.current'
      (from your comment)
      And it worked!
      Thanks for the help tho!

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

    This tutorial feels very lacking. I saw most of the solutions suggested to me led here although what we're seen here is not 2020+ couch party.. this is old 1990 couch party where you would want different controls for different player.
    My problem is both players using controllers (as it would actually happen in 2020+).
    This tutorial doesn't show how to use the same controller with the same exact inputs for two different players and more.. I recommend updating the tutorial if you found out how to crack this one., but I would not call this local multiplayer nowadays...

  • @spartadiunruly6212
    @spartadiunruly6212 3 роки тому

    Hi Sam would you mind making atutorial step by step on character creation using Unity Input System and Bolt together..Thanks..

    • @samyam
      @samyam  3 роки тому

      It’s on my huge list of future videos, perhaps one day I will! 😂

    • @spartadiunruly6212
      @spartadiunruly6212 3 роки тому

      @@samyam glad to see it coming

  • @GLArchitecturalGraphicsInc
    @GLArchitecturalGraphicsInc 3 роки тому

    if my players look different? I mean different prefabs

    • @samyam
      @samyam  3 роки тому

      You can override the behavior on the PlayerInputManager to join players manually, then manually call which prefabs you'd like to instantiate.

  • @boomboyag4614
    @boomboyag4614 3 роки тому +1

    Will this work with 2 controllers?

    • @samyam
      @samyam  3 роки тому

      Yeah it should! There might be some clashing issues where one control might override the movement of the other, but if you do have that issue check my pinned comment, I provide a similar example when 2 people want to use the same keyboard.

    • @boomboyag4614
      @boomboyag4614 3 роки тому

      @@samyam Ok! Thank you so much!

  • @Marythuu
    @Marythuu 3 роки тому

    How is it possible to create multiple players with one keyboard? I followed your instructions and created a second control scheme for ijkl, but everytime i want to "spawn" a second player nothing happens and the first player follows the instructions of ijkl aswell. Great video btw :)

    • @samyam
      @samyam  3 роки тому

      So I tried it out and I think the issue is the Player Input component is setting the default scheme on the Player and since it's using the same device it is not "including" the other control scheme. You could detect whenever the new control scheme is pressed and set the default for that player, however this article says creating a virtual keyboard worked:
      medium.com/@gb6d/two-players-one-keyboard-how-to-enable-multiple-players-in-the-same-device-with-unity-cd57853edc3f

    • @Marythuu
      @Marythuu 3 роки тому

      @@samyam Thank you so much for the quick answer! I wish there was a more graceful way to solve the problem, but even if i use multiple different keyboards unity still detects them as one input :/

    • @samyam
      @samyam  3 роки тому

      Even with the virtual keyboard mode? Maybe you can try posting on the Input System forum with the issue

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

    does this work with third person cinemachine setup

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

      nvm lol

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

      yep :)

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

      @@samyam I was wondering if the smooth camera script have rotation using the new input system

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

      You mean in my other video for smooth camera? No I didn’t implement that but shouldn’t be too bad for something simple. There is a way to use cinemachine with local multiplayer
      www.monkeykidgc.com/2020/12/unity-split-screen-multiplayer-using-cinemachine-follow-cameras.html

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

      @@samyam thankyou this helped a lot

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

    How can u add players depending on the controller u are using? kinda like street fighter game? Is it really difficult? Thanks.

  • @raaghavthapliyal2713
    @raaghavthapliyal2713 3 роки тому

    I get a error saying movementInput/jumped does not exist on the current context

    • @samyam
      @samyam  3 роки тому

      What’s the exact error? Make you there are no typos and you can also try regenerating the script from the input action asset

    • @raaghavthapliyal2713
      @raaghavthapliyal2713 3 роки тому

      @@samyam there are no typos

    • @raaghavthapliyal2713
      @raaghavthapliyal2713 3 роки тому

      @@samyam the error is
      jumped does not exist in the current context

    • @raaghavthapliyal2713
      @raaghavthapliyal2713 3 роки тому

      And
      movementInput does not exist in the current context

    • @samyam
      @samyam  3 роки тому

      Make sure you have that same variable name in your input action and in your script, it seems like there is something named differently. It’s difficult to tell without seeing the code, but you can double click the error message and go to the line where the error is to give you an indication.

  • @uqn1624
    @uqn1624 3 роки тому

    ASAP !! can @samyam you make one video with local multiplayer with 4 player for android touch control and every player must have to prepare the device to start the game. please there are very few video and all video is with 2 player.

    • @samyam
      @samyam  3 роки тому +1

      Hi, if they are all using separate devices it might be easier to use networking to connect the devices. I don't have a video planned of that sort, maybe these videos will help:
      ua-cam.com/video/3s6NUdK0o9Q/v-deo.html
      ua-cam.com/video/52-gpawpsFA/v-deo.html

    • @uqn1624
      @uqn1624 3 роки тому

      @@samyam thank you so much !

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

    Is there a reason why your using context.action.performed instead of using context.performed? i find that when i use context.action.performed the function gets called twice as opposed to just using context.performed where the function is only called once

  • @pagoda_dimensionale9761
    @pagoda_dimensionale9761 3 роки тому

    Sorry Sam I have seen the notification of your response to my vector3 spawn question…but the comment have disappear and I can’t read your answer 😭. Can you copy and paste under this comment and I hope it don’t disappear this time.

    • @samyam
      @samyam  3 роки тому +1

      In the player input manager there’s a player joined event you can subscribe to, and it gives you the player input component of the spanned character. You can get the gameobject from that (just call .gameObect on that component) and set the transform to what you like. Hope that helps!

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

    source code -> patreon , fuck no