No video

Local Multiplayer with NEW Input System - Unity Tutorial

  Рет қаралды 82,895

samyam

samyam

Күн бұрын

Пікірлер: 231
@samyam
@samyam 3 жыл бұрын
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.
@jacobhuppertz5625
@jacobhuppertz5625 2 жыл бұрын
Man. You never fail to give exactly what Im looking for. Thank you so much for these videos
@zukipmnow4445
@zukipmnow4445 2 ай бұрын
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!
@zapposh
@zapposh 3 жыл бұрын
Wonderful, I was secretly hoping you would make a video one day on exactly THIS! Thank you :-)
@samyam
@samyam 3 жыл бұрын
Nice! 😄
@rumblebox_
@rumblebox_ 3 жыл бұрын
These are easily some of the best Unity tutorials on KZfaq. Great video!
@spencerkoenig7267
@spencerkoenig7267 Жыл бұрын
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
@benlindquist3302
@benlindquist3302 2 жыл бұрын
That was a very good tutorial, you got to the point and didn't waste my time, well done.
@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 жыл бұрын
Yes it’s been a long time coming, thanks for watching!
@guayard
@guayard Жыл бұрын
It's a magic! Thank you so much! I love you samyam, you are the best!
@Myspacemeta
@Myspacemeta Жыл бұрын
Best Unity tutorials on YT. Thank you so much for this!
@bhavya.prashant
@bhavya.prashant 3 жыл бұрын
Woah! What a timing! Just what I was looking for. Brilliant tutorial.
@DavidB-rx3km
@DavidB-rx3km 2 жыл бұрын
I found a way of getting using the same pad/keyboard method - add two action maps, and put each of the actions relating to each player in them. Don't forget to add each of the player's settings in the events
@neenaw
@neenaw 3 жыл бұрын
Excellent as always 🙏🏾
@antontheyeeter
@antontheyeeter 3 жыл бұрын
Thanks that was exactly what i needed
@ColdOneK
@ColdOneK 3 жыл бұрын
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!!
@lostandfound2893
@lostandfound2893 2 жыл бұрын
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.
@ooDEFENDERoo
@ooDEFENDERoo 3 жыл бұрын
Thank you very much! Very useful tutorial!
@markes4465
@markes4465 2 жыл бұрын
Exactly what I was looking for! Great video!
@samyam
@samyam 2 жыл бұрын
Thanks!
@Sillymonkeies
@Sillymonkeies 2 жыл бұрын
Thanks Samyam! Really appreciate this video :)
@javierIglesias-b3q
@javierIglesias-b3q 2 жыл бұрын
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.
@sirpugstudios
@sirpugstudios 4 ай бұрын
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?)
@TheRealKaiProton
@TheRealKaiProton Жыл бұрын
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.
@THExRISER
@THExRISER Жыл бұрын
Thank you.
@disorderlygage1184
@disorderlygage1184 2 жыл бұрын
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 2 жыл бұрын
Check my pinned comment! You can manually instantiate players with different prefabs as needed :)
@incrediblegaming0910
@incrediblegaming0910 4 ай бұрын
does anyone know why in the player controller function why onMove and onJump dont show up? (im doing this in 2D mode btw)
@songwonchoi1679
@songwonchoi1679 2 жыл бұрын
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
@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?
@krazykase3419
@krazykase3419 Жыл бұрын
I am using a fps controller but when i add two players both of them move.
@morganowen3543
@morganowen3543 2 жыл бұрын
Thanks! This was really useful!
@snell9444
@snell9444 3 жыл бұрын
Love your Tutorials :)
@Bravehearte
@Bravehearte 3 жыл бұрын
Nice tutorial, thanks for sharing.
@samyam
@samyam 3 жыл бұрын
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 :)
@jmscshipp
@jmscshipp Жыл бұрын
Great video, thank you!
@quboss2008
@quboss2008 Жыл бұрын
THANKK YOUUU
@swiftcreations
@swiftcreations 2 жыл бұрын
So helpful! Thank you!
@benjoe1993
@benjoe1993 2 жыл бұрын
Very good tutorial. Thank you so much :)
@MBM_first
@MBM_first 3 жыл бұрын
thx for this vid it helped me a lot :)
@abdulkadirdursun6072
@abdulkadirdursun6072 3 жыл бұрын
Great video. Thanks a lot :D
@LuhDuckster
@LuhDuckster 2 жыл бұрын
Thanks alot for this tutorial this helped alot, I can't seem to figure out how to assign a gamepad to a gameobject with PlayerInput in the scene without spawning it when pressing a button. I need them both to exist at the start of the game
@alexlik4197
@alexlik4197 2 жыл бұрын
I need help with this too! I can't find anything that helps.
@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
@neozoid7009
@neozoid7009 2 жыл бұрын
thanks for the the awesome tutoril
@TearyHumor
@TearyHumor 3 жыл бұрын
Awesome video and really well explained! Instant sub from me :)
@jean-michel.houbre
@jean-michel.houbre 3 жыл бұрын
You have a new subscriber!
@samyam
@samyam 3 жыл бұрын
Thank you!
@artohaapanen7764
@artohaapanen7764 Жыл бұрын
I have 2 gamepads (XBox) and 2 characters, but they both move at the same time. How do I prevent this?
@marcos.rodrigues
@marcos.rodrigues Жыл бұрын
I'm having the same issue
@Me-ji7uq
@Me-ji7uq Жыл бұрын
Can you add two controllers? If yes then how?
@walbobo
@walbobo Жыл бұрын
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
@chickencow1598
@chickencow1598 4 ай бұрын
is this possible with 2 controllers
@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.
@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.
@RoySamaFR
@RoySamaFR Жыл бұрын
Is there a way to assign device to player that is ALREADY in the scene ?
@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)))
@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 kzfaq.info/get/bejne/f6mYZL12xry5mpc.html We also have a Discord channel where you can ask in the help channel with more detail discord.gg/Eu9462Jq
@Ghostgamer3535
@Ghostgamer3535 Жыл бұрын
How do I get the start and release Button information in OnJump(). Want to make a jump like in mario holding down to increase hight. But I cannot understand how to do it with this. I know how to do it with singel player using WasPerformedThisFrame, and WasReleasedThisFrame(). I just don't know how to write it with local 2 player in mind.
@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
@luxis14th25
@luxis14th25 3 жыл бұрын
Best tutorial on the new input system i've watched, it helped me a lot
@tmhugin8312
@tmhugin8312 2 ай бұрын
How could I get the position data from the spawned players?
@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!
@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
@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.
@bossfakealeks12345
@bossfakealeks12345 3 жыл бұрын
If possible can there be a part 2
@samyam
@samyam 3 жыл бұрын
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 жыл бұрын
Gotcha, I'll take it into account for a possible future video!
@bossfakealeks12345
@bossfakealeks12345 3 жыл бұрын
samyam thx
@raaghavthapliyal2713
@raaghavthapliyal2713 3 жыл бұрын
@@bossfakealeks12345 that would be good
@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 жыл бұрын
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 🙏
@ilyasyildiz6091
@ilyasyildiz6091 3 жыл бұрын
Good Job
@imrsvhk
@imrsvhk Жыл бұрын
Would this kind of approach work for A VR setup on Android running quest/pico headset?
@artohaapanen7764
@artohaapanen7764 Жыл бұрын
What do I need to change if I want two different game characters?
@CiampaGiuseppe8
@CiampaGiuseppe8 Жыл бұрын
I have a question: does make sense to add a different Player Input Manager for each player?
@hoomanhoney
@hoomanhoney 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Yeah just make sure in the input action to select keyboard or controller for that corresponding action 🙂
@P_tricc
@P_tricc 3 жыл бұрын
Great tutorial, could you make a tutorial on swipe detection with the new input system?
@samyam
@samyam 3 жыл бұрын
I'll put it on my list!
@pourmydrank
@pourmydrank 3 жыл бұрын
your fingers are machines!!
@samyam
@samyam 3 жыл бұрын
🖖
@booksforlife7903
@booksforlife7903 3 жыл бұрын
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 (kzfaq.info/get/bejne/f6mYZL12xry5mpc.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
@shendtytynxhiu8075
@shendtytynxhiu8075 3 жыл бұрын
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 жыл бұрын
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 жыл бұрын
Thanks!
@laurentcharles7179
@laurentcharles7179 Жыл бұрын
Hello, I wonder how to use 2 joysticks to control different players, is that supported in vanilla unity?
@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
@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 !
@kilabeann
@kilabeann Жыл бұрын
Would this still work if I used 2 game padd
@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/
@jasithiss
@jasithiss Жыл бұрын
What about 2 controllers?
@orpheuscreativeco9236
@orpheuscreativeco9236 3 ай бұрын
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 👍
@LostAngel175
@LostAngel175 9 ай бұрын
Can i use this in Genarate C# class?
@mr.soulless904
@mr.soulless904 2 жыл бұрын
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 2 жыл бұрын
Make sure you have 2 separate control schemes for the two different players, check my pinned comment for more information.
@mr.soulless904
@mr.soulless904 2 жыл бұрын
@@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
@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 kzfaq.info/get/bejne/nJanlNtpsdvKoYU.html
@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!
@raaghavthapliyal2713
@raaghavthapliyal2713 3 жыл бұрын
i am also doing this in 2d
@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!
@doubled9645
@doubled9645 3 ай бұрын
goated
@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)
@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 жыл бұрын
I think it'd be best to create a different schema for each player so the Player Input Manager doesn't get confused.
@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.
@samiduzgun
@samiduzgun 3 жыл бұрын
very good
@sinlessdragon6514
@sinlessdragon6514 3 жыл бұрын
Valeu!
@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
@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.
@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...
@alxoseal517
@alxoseal517 3 жыл бұрын
@samyam Help, it won't let me jump (or in my case, shoot) It tells me this error (if you can help me!) : InvalidOperationException while executing 'started' callbacks of 'PC / Shoot [/ Keyboard / m]' UnityEngine.InputSystem.LowLevel. C__DisplayClass7_0: b__0 (NativeInputUpdateType, NativeInputEventBuffer *) UnityEngineInternal.Input.NativeInputSystem: NotifyUpdate (NativeInputUpdateType, IntPtr) (at C: /buildslave/unity/build/Modules/Input/Private/Input.cs: 117) InvalidOperationException: Cannot read value of type 'Boolean' from control '/ Keyboard / m 'bound to action' PC / Shoot [/ Keyboard / m] '(control is a' KeyControl 'with value type' float ') UnityEngine.InputSystem.InputActionState.ReadValue [TValue] (System.Int32 bindingIndex, System.Int32 controlIndex, System.Boolean ignoreComposites) (at Library/PackageCache/com.unity.inputsystem@1.0.1/InputSystem/Actions/InputActionStatem/Actions/InputActionStatem/Actions/InputActionStatem/Actions/InputActionStatem 2020) UnityEngine.InputSystem.InputAction + CallbackContext.ReadValue [TValue] () (at Library/PackageCache/com.unity.inputsystem@1.0.1/InputSystem/Actions/InputAction.cs: 1433) PlayerControllerPC.OnAtack (UnityEngine.InputSystem.InputAction + CallbackContext context) (at Assets / Scripts / PlayerControllerPC.cs: 43) UnityEngine.Events.InvokableCall`1 [T1] .Invoke (T1 args0) (at C: /buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent.cs: 207) UnityEngine.Events.UnityEvent`1 [T0] .Invoke (T0 arg0) (at C: /buildslave/unity/build/Runtime/Export/UnityEvent/UnityEvent/UnityEvent_1.cs: 58) UnityEngine.InputSystem.Utilities.DelegateHelpers.InvokeCallbacksSafe [TValue] (UnityEngine.InputSystem.Utilities.InlinedArray`1 [System.Action`1 [TValue]] & callbacks, TValue argument, System.String callbackName, System.Object context) (at context Library/PackageCache/com.unity.inputsystem@1.0.1/InputSystem/Utilities/DelegateHelpers.cs: 51) UnityEngine.InputSystem.LowLevel. C__DisplayClass7_0: b__0 (NativeInputUpdateType, NativeInputEventBuffer *) UnityEngineInternal.Input.NativeInputSystem: NotifyUpdate (NativeInputUpdateType, IntPtr) (at C: /buildslave/unity/build/Modules/Input/Private/Input.cs: 117)
@alxoseal517
@alxoseal517 3 жыл бұрын
this is my script: using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.InputSystem; public class PlayerControllerPC : MonoBehaviour { public float Speed = 5f; Vector2 movement; private bool shoot = false; public Rigidbody rb; private CharacterController controller; public GameObject bullet; private void Start() { controller = gameObject.GetComponent(); } private void Update() { Vector2 move = new Vector2(movement.x, movement.y); controller.Move(move * Time.deltaTime * Speed); if(shoot) { Debug.Log("YOu SHOOT:PC"); } controller.Move(move *Speed * Time.deltaTime); } public void OnMove(InputAction.CallbackContext context) { movement = context.ReadValue(); } public void OnAtack(InputAction.CallbackContext context) { shoot = context.ReadValue(); shoot = context.action.triggered; } private void FixedUpdate() { // rb.MovePosition(rb.position + movement * Speed * Time.deltaTime); } }
@samyam
@samyam 3 жыл бұрын
the shoot read value bool is incorrect, it reads a type of float. Also you are overriding that value with triggered right after, I would either delete that function and use triggered or remove the triggered part
@alphaanar2651
@alphaanar2651 3 жыл бұрын
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 жыл бұрын
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!
@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
@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 жыл бұрын
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
@dushes_botalov
@dushes_botalov 3 жыл бұрын
Nice 🥴👍
@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.
@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 жыл бұрын
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!
@boomboyag4614
@boomboyag4614 2 жыл бұрын
Will this work with 2 controllers?
@samyam
@samyam 2 жыл бұрын
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 2 жыл бұрын
@@samyam Ok! Thank you so much!
Local Co-op in Unity using the New Input System - Tutorial
19:41
Broken Knights Games
Рет қаралды 45 М.
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 33 МЛН
The Joker saves Harley Quinn from drowning!#joker  #shorts
00:34
Untitled Joker
Рет қаралды 66 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 54 МЛН
wow so cute 🥰
00:20
dednahype
Рет қаралды 13 МЛН
The comments on my game were interesting....
9:00
samyam
Рет қаралды 18 М.
Why these weird indie games BEAT the AAA industry
9:08
samyam
Рет қаралды 17 М.
choosing a game engine is easy, actually
15:08
samyam
Рет қаралды 433 М.
every step to actually make your dream game (then sell it)
24:27
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 705 М.
Why Making Multiplayer Games SUCKS
6:46
Tom Weiland
Рет қаралды 418 М.
Local Multiplayer and Split-Screen - New Input and Cinemachine
13:37
One Wheel Studio
Рет қаралды 28 М.
Stay on your way 🛤️✨
00:34
A4
Рет қаралды 33 МЛН