Local Co-op in Unity using the New Input System - Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 พ.ย. 2024

ความคิดเห็น • 135

  • @DigitomProductions
    @DigitomProductions 4 ปีที่แล้ว +8

    Very interesting approach here...I like that the different inputs are being spawned in vs spawning in whole player prefabs with the inputs attached. Thanks for showing this!

  • @Laatikottaja
    @Laatikottaja 4 ปีที่แล้ว +14

    Thank you for this video, and for including the project files!
    For some reason when I tried making PlayerInput-prefab, it reset the Events->PlayerMovement reference to players. I didn't realize that you must reference the PlayerInput itself inside, instead of the players to access the OnMovement, but your files helped me locate the problem. I did undestand the need to reference Player1 or Player2, but its absurd that the prefab has to reference itself..

    • @jmmpptd
      @jmmpptd 4 ปีที่แล้ว

      You are a life savior

    • @kolehmainen6678
      @kolehmainen6678 2 ปีที่แล้ว

      Suomalainen? Finnish?

  • @caasi151
    @caasi151 4 ปีที่แล้ว +11

    Around 15:00 and 16:00 your PlayerInput prefab contained the the OnMove as the function (in the Callback context of the Player Input component). The OnMove is wrote in the PlayerInputHandler script which is attached to the player prefab at first, so no problems there, but further on you delete this script on the Player prefab, when I does this it removes the OnMove parameter of the Callback context as the player object doesn't have the OnMove method anymore. I fixed the problem by attaching the PlayerInput prefab to the Player Input callback context component so I was able to select the OnMove as a function back again.
    I think that the sneaky cut between 16:38 and 16:39 fixed it but even if you didn't want to show it you should have say what you've done even quickly. You'll improve in explaining us how you do such cool coding things, I trust in you !

    • @BAgodsmack
      @BAgodsmack 2 ปีที่แล้ว +1

      Appreciate your comment! Weren't able to figure out the fix on my own.

  • @downthecrop
    @downthecrop 11 หลายเดือนก่อน

    The reprefab being strictly a playerinput and mapping it to a given statemachine is a good idea. I am using this for my game now!

  • @yojan69
    @yojan69 ปีที่แล้ว

    tysmm, i really didnt understand a heck out of every single other tutorial about the exact same thing, now with this tutorial, i finally understood how it actually works, and i really liked your approach to instantiate the player input instead of the whole player, really cool

  • @erosjagatpulagana6403
    @erosjagatpulagana6403 4 ปีที่แล้ว +2

    I like the approach there, it solved my problem with 'only 1 player prefab' in the input manager. Thank you so much!

  • @moocowp4970
    @moocowp4970 4 ปีที่แล้ว +5

    This was great! I tried following other tutorials to do something similar, but they didn't get nearly as nice a result as yours :) This was very helpful, thanks, liked and subscribed, will definitely be checking out your other videos too.
    One minor piece of feedback: I found at some points throughout the video that an explanation of 'why', or what the various methods/classes we were calling were doing, could have been useful; e.g. at parts, such as the movers.FirstOrDefault() line (i just didnt know what that method did), I didn't really understand why I was doing something or what consequence it would have, I just copied it dutifully (and then later looked up the methods etc.). I think its fine to expect us to look up a few things (we are trying to learn after all), but equally it might make the video make more sense if we always know why we are typing particular lines of code or adding particular components.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +4

      Thanks for watching and you make some very good points 👍 I'll try to be more mindful to explain more.

  • @jbacon22
    @jbacon22 3 ปีที่แล้ว

    Thanks man I'm surprised how long I googled before I finally found your vid which gave me the info I needed to move forward. Thanks again.

  • @contrahorizon2192
    @contrahorizon2192 3 ปีที่แล้ว +1

    I really can't thank you enough for this tutorial

  • @dapyr
    @dapyr 2 ปีที่แล้ว +3

    For some reason only my first controller works. So whenever I use my 2nd controller nothing happens :/
    Do you know of any reasons why this might be happening?
    Also is it possible to make KB+M seperate from the first controller as well? (so KB+M is player1 and Controller1 is P2, now they are both P1)

  • @ashrewsberry7698
    @ashrewsberry7698 4 ปีที่แล้ว +4

    This has been helpful, thanks a bunch

  • @XtremeAleatorio
    @XtremeAleatorio 2 ปีที่แล้ว +2

    Thanks for the video man. But I have a problem, FirstOrDefault gives me an error even tho i added the using System.Linq; i dont know how to solve it or if theres a diferent way to do it.

  • @seijinwright9296
    @seijinwright9296 2 ปีที่แล้ว

    This was a great tutorial! Thank you so much!

  • @Kudoshi
    @Kudoshi 4 ปีที่แล้ว

    I have just tested. This indeed works.

  • @PPLorux
    @PPLorux 4 ปีที่แล้ว

    Just what I was looking for. Thanks!

  • @natalia-mf1vw
    @natalia-mf1vw 4 ปีที่แล้ว +10

    Hello, all the code was going well until I reached the FirstOrDefault part. It says that mover does not contain the definition "FirstOrDefault" and no accessible extension method accepting a first argument type Mover (are you missing a using directive or an assembly reference?). I included the using system.linq at the top of my code too. I don't get why I can't access the FirstOrDefault function.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +2

      Thanks for watching! Sounds like you are almost there, but when you add a namespace reference remember it will be case sensitive, so it will need to be "System.Linq" not system.linq. If you are still having trouble try downloading my project from Git Hub (link in description) and compare your script with the one I wrote to see if there are any other differences that might be contributing to the error you are seeing.

    • @ryangray7748
      @ryangray7748 4 ปีที่แล้ว +1

      @@brokenknightsgames7966 I'm getting the same issue. I checked your code versus mine, line for line, and the error still persists. My casing is correct as well. Is there anything else that you can think of that may be causing the error?

    • @DavidInschlag
      @DavidInschlag 4 ปีที่แล้ว +13

      @@ryangray7748 i've had the sameissue... in my case it was a typo, i used FindObjectOfType instead auf FindObjectsOfType, so of course no list got created .. Autocomplete is a *** sometimes ^^

    • @dairyfreelemongaymes7810
      @dairyfreelemongaymes7810 4 ปีที่แล้ว +4

      @@DavidInschlag THANK YOU I NEVER WOULD HAVE NOTICED THIS D: This fixes everything

    • @moocowp4970
      @moocowp4970 4 ปีที่แล้ว +2

      @@DavidInschlag Thank you! I was having the exact same error, and I knew it was user error on my part but couldn't for the life of me see the problem haha.

  • @crudecharacters2716
    @crudecharacters2716 4 ปีที่แล้ว +3

    The movement Callback Event in PlayerInput should be referencing the Player Input Handler Script directly not through the player. Had me confused for a bit, im not a programmer. Also Thank you so much for this!!

    • @yousefantonio1494
      @yousefantonio1494 3 ปีที่แล้ว

      i know it is kinda randomly asking but does anybody know of a good website to watch newly released tv shows online ?

    • @joncaiden9496
      @joncaiden9496 3 ปีที่แล้ว

      @Yousef Antonio flixportal =)

    • @yousefantonio1494
      @yousefantonio1494 3 ปีที่แล้ว

      @Jon Caiden Thank you, I went there and it seems like they got a lot of movies there :D Appreciate it!

    • @joncaiden9496
      @joncaiden9496 3 ปีที่แล้ว

      @Yousef Antonio You are welcome =)

  • @____---__________--------_____
    @____---__________--------_____ 4 ปีที่แล้ว

    Thanks for the tutorial man! really helpful

  • @manupkmntrainer8391
    @manupkmntrainer8391 4 ปีที่แล้ว

    Thanks a lot, your video was the best explained I found :D

  • @bradm7050
    @bradm7050 3 ปีที่แล้ว

    Legend. Thanks so much!

  • @noodleplexium5953
    @noodleplexium5953 4 ปีที่แล้ว +3

    FirstOrDefault() is underlined in red?

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Probably need to add an import "using System.Linq" at the top of the script file

    • @vonstudios2028
      @vonstudios2028 4 ปีที่แล้ว +1

      i have the same problem

  • @gilbertobitt3757
    @gilbertobitt3757 4 ปีที่แล้ว

    Amazing... Thanks for this information.

  • @recallmycode
    @recallmycode 3 ปีที่แล้ว +1

    Great tutorial, but I did everything said and still only am able to join one playerInput prefab whenever I press a button on the other controller it doesnt work

  • @NapkinHolder_AH
    @NapkinHolder_AH 4 ปีที่แล้ว +3

    When I make a path for the controller, it only says usages and not gamepad, what's wrong?

    • @jmscshipp
      @jmscshipp 4 ปีที่แล้ว +2

      I fixed this by going to the top left of the window and adding a control scheme!

  • @Jooseephh
    @Jooseephh 4 ปีที่แล้ว +1

    just saying at 15:26 he does a jump cut where he has filled back in all of the events using the input handler script from the prefab object i totally missed this so if anyone has an issue where your character wont do anything that might be why

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Thanks for pointing this out, I will add a timestamp note in the description.

  • @אור-יםביבירובי
    @אור-יםביבירובי 4 ปีที่แล้ว +3

    I can't use the action map altho my controller is connected and unity registers it, I can press on the add a bind but I can't add the button via the Path dropDown and there is nothing there

  • @damianoschirinzi4317
    @damianoschirinzi4317 3 ปีที่แล้ว +1

    Really helpful! Thankyou! Did you ever work out what the null reference was or a fix other than the if statement check?

    • @wtmftproductions
      @wtmftproductions 3 ปีที่แล้ว

      After watching the video multiple times, I'd bet that it's because when he initially made the "PlayerInput" game object have Unity Events linked to objects in the scene, but then sets it as a prefab. I could be wrong, but I think that caused a problem.

  • @DrFross09
    @DrFross09 2 ปีที่แล้ว

    FINAL-FUCKING-LY!
    worked right away... now I just gave to finagle this set up into my game without breaking anything.

  • @babasheep2828
    @babasheep2828 2 ปีที่แล้ว +1

    Hey! The select screen works great, and moving the player is fine, but when I added shooting, the game breaks saying “cannot read (shoot button here) as a Vector2 value. Any ideas?

  • @tobyk5091
    @tobyk5091 4 ปีที่แล้ว +2

    When I click on Path under the Binding settings I can’t find Gamepad even though I included it in the Project Settings

    • @gabrielchammo8378
      @gabrielchammo8378 4 ปีที่แล้ว

      Ye Same

    • @ticktockclook2617
      @ticktockclook2617 3 ปีที่แล้ว +1

      go back to settings and leave it blank do not do game pad

    • @tobyk5091
      @tobyk5091 3 ปีที่แล้ว

      @@ticktockclook2617 thanks yeah I figured that out through painful trial and error

    • @braxtonsdev9564
      @braxtonsdev9564 3 ปีที่แล้ว

      @@ticktockclook2617 thank you, very helpful

  • @flarigrar7114
    @flarigrar7114 4 ปีที่แล้ว +3

    I tried using this tutorial for single button actions, but they get called 3 times (I have an attack function with a combo system, but it calls Attack() 3 times, which is not what I want). What do you think is the problem?
    Edit: I've solved the problem. The if statement for all of the single button actions (like jumping) will have to look like this; if(mover != null && context.performed) I used mover as a character controller example since that's what's in this video.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Hey glad you solved your issue. One thought I had is, perhaps the action is triggering on button pressed instead of press and release. You can configure the interactions for each button in the dialog where you set up your different action maps. (see 5:58 for example of the window I am referencing)

    • @flarigrar7114
      @flarigrar7114 4 ปีที่แล้ว +1

      @@brokenknightsgames7966 I did that, but that didn't do anything. You have to do context.performed or else it'll just go through each possible interaction (pressed, held, and released)

    • @user-rp8vl5jl9c
      @user-rp8vl5jl9c 4 ปีที่แล้ว +1

      I have the same problem, but your fix didn't do it for me. The function I want to use for an action doesn't have any parameter(or context), I tried to put it like SelectRight(CallbackContext context) and make an if function within it which checks it the context was performed for the sake of it, but it didn't work... Think you can help me out a bit?

  • @psyconiusCthulhu
    @psyconiusCthulhu 4 ปีที่แล้ว

    Awesome tutorial man.. You definitely boiled this down way better than any other tutorial I've watched. Got my input migrated to the new system thanks to you. However... My goal is split screen multiplayer.. It's 5 player, one VR rig and 1-4 others sharing a screen. The Input Manager is totally cool if I am just using 4 gamepads. Which.. for couch multiplayer is what the aim would be. However, I plan to utilize the Steam play together or whatever their virtual local co-op is going by these days so I really would like them to have the option for mouse/keyboard. Now that I've given you my life story, my question is.. how do you get the Input Manager to handle mouse AND keyboard as ONE control scheme? As it stands.. Moving the mouse will add the mouse as a controller and then hitting the keyboard will add the keyboard as another. I've not found much with the google box.. I have a sinking feeling that needs to be handled in code rather than the plug and play sexiness of how the IM handles controller detection.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Thanks for watching, your project sounds Interesting and ambitious.. I think you might have code your own component with the input system API that does more than the provided PlayerInput component in order to read multiple devices at the same time, however I am almost certain you can read from the mouse and keyboard at the same time with the built in components for that player.

    • @psyconiusCthulhu
      @psyconiusCthulhu 4 ปีที่แล้ว

      @@brokenknightsgames7966 further googling looks like one of the absolute reasons for the control scheme groups is to link up devices and require them being dependent on each other. My first try at doing this failed miserably. However, my first run at implementing your solution was broken too until I just literally deleted the PIM component and readded it. Unity is fuuuuuun sometimes 🙄
      I'm gonna hit up your split screen tutorial tonight to see what I can... Borrow.. From you. Keep up the good work!

    • @psyconiusCthulhu
      @psyconiusCthulhu 4 ปีที่แล้ว

      @@brokenknightsgames7966 update. Using the grouped input scheme seems to have worked this time. I also switched it to join when action is triggered. Made a button for gamepad and a keyboard button. Works like a charm. Apart from fine tuning the movement to not just be more fluid I have it and split screen up and running. My only other weirdness comes in that looking with mouse delta axis or even right stick gamepad is WAAAAAAY too sensitive normally. I had to use the factor scale to like 0.1 for mouse and it is still ridiculous(and my own sensitivity float is only 2).

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Glad you figured it out 👍 never stop tinkering!

  • @iulianatintiuc959
    @iulianatintiuc959 2 หลายเดือนก่อน

    Hi! I followed your tutorial but when i get to the end part, the other player doesnt move. I'm using the WASD movement for the players. Any help?

  • @YaqoobMalik-v9r
    @YaqoobMalik-v9r ปีที่แล้ว

    Want to point out an error i had that took me hours to solve. I couldnt access playerindex because i had called the input action asset PlayerInput, renaming this (and deleting the old C# class generated by it) fixed my problem

  • @donrigo
    @donrigo 4 ปีที่แล้ว +1

    hello there. first of all great videos. nice pace and smooth voice ;)
    but i have the issue that i can't access the playerindex in the playerindex script. I also get the error that the getcomponent needs an component or monobehaviour. Not sure since the playerinput generate the c# script. i also have the gameobject playerinput in the scene where i try to edit the script. the script is also already on the player prefabs. any idea?!

  • @guitarjack3217
    @guitarjack3217 2 ปีที่แล้ว

    Does anyone know how I could get the input handeler to work with animations? I have two different animation scripts for my different prefabs. (fyi I changed his code a bit to select different prefabs instead of colors), any ideas?

  • @hihiho01
    @hihiho01 4 ปีที่แล้ว +1

    These errors are due to the fact that you are somehow using two objects with the input system, on scene and in the project files. I struggle with it myself and I have no idea what's going on :D This only happens when you use input player manager component ;D

    • @ralfaralf6805
      @ralfaralf6805 3 ปีที่แล้ว

      I still have the same problem and found no elegant solution so far

  • @wtmftproductions
    @wtmftproductions 3 ปีที่แล้ว

    This is awesome, but can you do a tutorial showing the use of other buttons? Seems this whole thing breaks down when you try to execute a function as a result of the gamepad trigger pull. If you call any functions from within the function receiving the callback, it causes a null ref exception.

    • @valter_tk2479
      @valter_tk2479 2 ปีที่แล้ว

      i have the same problem when i try to make my ship shoot, if you have found the solution pls respond to this am so stuck in this.

  • @penguin_spy6122
    @penguin_spy6122 ปีที่แล้ว

    When I tried adding a camera script to basically move the camera to the midpoint between the characters whilst using this setup, the camera script messed with the player movement - when controlling one character the other moved aswell but inverted (it also didnt call the run animation in the other player) any idea why or how I can make a camera script that will work with this please?

  • @Dailyfiver
    @Dailyfiver 3 ปีที่แล้ว

    OnMove(); doesnt show up for me. Like it isnt being recognized in Visual Studio for some reason. Help! I'm a newbie.

  • @eruz684
    @eruz684 4 ปีที่แล้ว +1

    Hi Thanks for the tutorial, I am new to unity but I try and create a two players game but the second player is a helper meaning it simply follows the main player and attacks enemies and heals and triggers special attacks but whenever the player moves it has to stop whatever it is doing and follows the main player. I have no idea how to do this in unity . what would you suggest thanks

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +1

      I would start with trying to break up the problem into smaller manageable parts. Perhaps create a script that does one of those things you described, then once it's working, create another script to handle the next small piece of functionality.

  • @giorgiodispenza2266
    @giorgiodispenza2266 3 ปีที่แล้ว

    If I want to add an action with a button input?

  • @heather42404
    @heather42404 3 ปีที่แล้ว

    When I got to 17:25, I ran into the same error as the video, but I have no idea how to debug the code. Could I have some help?

  • @reviewbyme681
    @reviewbyme681 หลายเดือนก่อน

    I followed you step by step but i don’t know why i am not getting on move in function if anyone know please let me know….

  • @micah7621
    @micah7621 4 ปีที่แล้ว +1

    Thanks a lot for the tutorial! Very much appreciated. Just a question. I've been trying to set it up so that the players don't have to press a button to join. I see that the Player Input Manager can change the Join Behaviour to "Join Players When Join Action is Triggered" or "Join Manually" but I can't figure out how to use them. Would it be something you call from script? I'll be doing more googling and trial and error in the meanwhile. Thanks!

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +3

      Yes, using other join behaviors would require scripts that leverage the new input API. One benefit by using "on button press" is the input system handles the device to player pairing for you where as by doing it all manually in your code you would need to figure out what devices should go each player. The new input API is pretty extensive and you can do a lot with it. Best of luck to you and keep hacking away, it's the best way to learn 🙂

    • @micah7621
      @micah7621 4 ปีที่แล้ว

      @@brokenknightsgames7966 Thanks!

  • @beckyboy1
    @beckyboy1 2 ปีที่แล้ว

    I have encountered 2 issues early on in the tutorial and I was wondering if anyone could help. About 6 minutes into the video he sets up the movement with "left stick". Here is where I encounter the issue. In the input system package I made the supported device "gamepad" just as he does in the video. However when I do that, I then go under movement and when I try and bind it to a button, the only thing that pops up is "usage". There is no option to select any controller inputs.
    My second issue is if I don't select game pad in the input system package tab as supported device, then I get a whole list of things to bind the controls to. This includes the gamepad. However, when I try and bind it to the left stick, I can't do just the left stick, I can only do "left stick down", "left stick up", "left stick left", or "left stick right". But it won't let me choose specifically the left stick.
    Does anyone know how to help with any of these issues?
    Edit: It's not registering anything that I put under "supported devices" it's not just the gamepad

    • @alexhogenson1799
      @alexhogenson1799 2 ปีที่แล้ว

      I don't have an immediate solution to your first problem, but the second problem can be solved by clicking the " Movement" Action, then in the Action Properties column, set Action Type = "Value" and Control Type = "Vector2. Then when you add a Binding under "Movement", you should see Left Stick as an option under Gamepad.
      Hope this helps!

  • @sumogre1822
    @sumogre1822 4 ปีที่แล้ว

    I'm having a problem where the Player Input doesn't call any functions. Any ides why?
    Update: It's working now when i removed control schemes

  • @unpinguindeter6723
    @unpinguindeter6723 4 ปีที่แล้ว +1

    i cannot create a mover variable

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      If you run into any issues with writing scripts while following along, you can always download or see the finished project and scripts in my GitHub repo to see what is different (link in the description).

  • @GhosttheassassinSJ
    @GhosttheassassinSJ 3 ปีที่แล้ว

    I cannot find Add 2d Vector Composite, can anyone help out here

  • @caasi151
    @caasi151 4 ปีที่แล้ว +1

    At 15:28 you cut a frame of the video where you actually did something that we also need to know how to do, it's simple and not very difficult but still, it's pretty hard to follow sometimes especially when you do quick cuts and not even explaining what you've done during the cut. Otherwise it's very instructive but can be hard to follow at times.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Thanks for the feedback and for pointing this out. I made an update to the description with a timestamp pointing this out as it is easily missed.

    • @caasi151
      @caasi151 4 ปีที่แล้ว +1

      @@brokenknightsgames7966 Cool ! I'm eager to finish this tuto and truly understand what I've wrote to follow your next biggest tuto on advanced local coop setup, even tho it's sometimes rushed you're doing a very good job !

  • @thomaseduardo7653
    @thomaseduardo7653 4 ปีที่แล้ว

    And taking advantage of your good will again, could you do a tutorial of a player selection passing the players trough scenes without having to call Join Behavior again?

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +2

      Yeah I'm thinking about doing a follow on video with a "player join" scene before the main level loads since that is a must have scenario for local co-op

    • @thomaseduardo7653
      @thomaseduardo7653 4 ปีที่แล้ว

      @@brokenknightsgames7966 oh nice, that would be great. I havent seen a tutorial doing so, even more in The New input system, doing a player multiplayer selection screen and passing those players through The scenes like @Gilbertobitt asked

  • @mrinky8129
    @mrinky8129 3 ปีที่แล้ว

    Any way to get this working in 2D?

  • @AetherXIV
    @AetherXIV 4 ปีที่แล้ว

    15:33 my playerinput gameobject loses it's references when I make it a prefab and I can't re-assign them from the edit window... anyone else having this problem?
    Edit: how to fix: double click on "player input prefab", in the PlayerInput Component, toggle down the "Events" window, drag "PlayerInputHandler" Script to source, select your methods

  • @1oglop1
    @1oglop1 3 ปีที่แล้ว

    I find this very confusing, everyone seems to be using their own wording some use *Manager, some use *Contoller, other things are Handlers, isn't there a recommended approach to naming things?

  • @gilbertobitt3757
    @gilbertobitt3757 4 ปีที่แล้ว

    that something i want to do for a long time.. now i can do it on the game menu to them set everything according the only thing i want to know is how to create this do dynamically create player when i change scene or i create a dummy and when change scene for a mini-game or change one of the player to another prefab how can i set this prefab(with player input) to a specific index based on player manager players list?

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      One approach that might work is you could have all the player input prefabs loaded in a separate scene that is loaded (additively) alongside whatever level or other scene you are currently on, that way the player inputs will persist from scene to scene. Then create a system that spawns the character avatar objects in the scene dynamically by getting the player information (player count, and player input) from the player input scene to "hook up" the input prefabs to the character avatar prefabs.

  • @dodi6765
    @dodi6765 4 ปีที่แล้ว

    can you pls not jumpcut when you find a problem ex. 15:29 i didnt get what you did

  • @Victornemeth
    @Victornemeth 4 ปีที่แล้ว

    i dont understand why in the moverscript on player 2 the playerindex would change to 1.

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      If I am understanding your question correctly it's because array indexes start at 0 not 1. So player 1's player index is 0 and player 2's index is 1

    • @Victornemeth
      @Victornemeth 4 ปีที่แล้ว

      @@brokenknightsgames7966 I mean, why does it increase without expliciet saying so

  • @MathieuHaas68
    @MathieuHaas68 4 ปีที่แล้ว

    Hey buddy!
    Nice video tbh but I have one question.
    Let's admit at first your game can be played solo but if someone plugs in another controller then it will create and instantiate a second player.
    That's the point I'm stucking on, everywhere :(

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      A second player will only be created if we configure the player input manager to do so.

  • @daveb7596
    @daveb7596 3 ปีที่แล้ว

    how do i instal linq.

    • @brokenknightsgames7966
      @brokenknightsgames7966  3 ปีที่แล้ว

      Add a reference to the namespace at the top of your script 'using System.Linq;'

  • @alextreme98
    @alextreme98 4 ปีที่แล้ว

    Can one player use the keyboard, and the other one the gamepad ?

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว

      Yes as long as you have both devices setup in the input bindings, you will also want to make sure you set up the player input managers to not automatically switch devices

    • @alextreme98
      @alextreme98 4 ปีที่แล้ว

      @@brokenknightsgames7966 lately we figure it out, we were in rush in a game jam, thanks for the answer, if you want to see the result, i can let you a link to the game once it is up on their webpage :D

    • @iulianatintiuc959
      @iulianatintiuc959 2 หลายเดือนก่อน

      @@brokenknightsgames7966 what do you mean by "make sure you set up the player input managers to not automatically switch devices"?

  • @thomaseduardo7653
    @thomaseduardo7653 4 ปีที่แล้ว

    Thanks man, it really helped me a lot! :)
    But taking advantage of your good will kkk, could you help me with a doubt? It's always giving me the error: "NullReferenceException: Object reference not set to an instance of an object" when i try to call a function from My "PlayerActions" script. But calling from the mover script gives me no error.
    I believe that the error comes because i got to create a "var" with the playerActions instance and than atribute a firtsOrDefault to it. But when i try, it gives me the error : "PlayerActions does not contain a definition for firstOrDefault". and it would be messy if i do all of my code in one script.
    The full error: UnityEngine.InputSystem.LowLevel.c__DisplayClass7_0:b__0(NativeInputUpdateType, NativeInputEventBuffer*)

    • @brokenknightsgames7966
      @brokenknightsgames7966  4 ปีที่แล้ว +1

      Sounds like you are using the FirstOrDefault function, did you import the System.Linq namespace?

    • @thomaseduardo7653
      @thomaseduardo7653 4 ปีที่แล้ว

      @@brokenknightsgames7966 yeah a did exactly as your example

  • @benji-o1204
    @benji-o1204 4 ปีที่แล้ว

    I lost you at 5:59. On my screen, there is no option for Gamepad.

    • @benji-o1204
      @benji-o1204 4 ปีที่แล้ว

      I fixed the problem!

    • @curmpet
      @curmpet 4 ปีที่แล้ว

      @@benji-o1204 how did you fix it because gamepad isnt there for me either nor keyboard or mouse

    • @benji-o1204
      @benji-o1204 4 ปีที่แล้ว

      @@curmpet I accidentally removed one of the scripts.

    • @curmpet
      @curmpet 4 ปีที่แล้ว +1

      ​@@benji-o1204 oh im doing this in my own project but i fixed it by adding a control scheme for each input device which then let me select the bindings

  • @vihaannagarkar1870
    @vihaannagarkar1870 10 หลายเดือนก่อน

    I am having an issue where after I spawn the second player, one controller controls both players which is not what I want. I want the two controllers to control each player separately. How do I fix that?

    • @Demisemæn
      @Demisemæn 5 หลายเดือนก่อน

      Read your Code, understand the tutorial, dont copy

  • @DavidB-rx3km
    @DavidB-rx3km 2 ปีที่แล้ว

    Get rid of the music and video in the bottom right, we don't need to see/hear them thanks

  • @rodrigogarduno8115
    @rodrigogarduno8115 ปีที่แล้ว

    crack

  • @xenogamingllc
    @xenogamingllc 4 ปีที่แล้ว

    Really good tuto thanks for this bro!