Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by cjdabeast99 · Nov 16, 2021 at 01:42 AM · gamepadinputsassignment

Assign Gamepad To Specific Player Input In New Scene

Hello, I've recently run into a standstill in my game that is like Mario Kart. I have a Menu scene that has a player input system and I need some type of method to get say Player 1's assigned gamepad and assign it in the next scene to Player 1. As of rn, both scenes require a player to press a button to join. The problem with this is that in the Game scene when a player joins the order of who's player 1,2,3,4 get's messed up causing players not to spawn as the character they selected. Plus I want the player to spawn automatically and already be assigned the correct corresponding gamepad. It's rather inconvenient to make all players ready up before the game may begin.

My idea as of rn is to use Gamepad.current and to save this as a global var and assign players for example:

 if(Gamepad.current == GameObject.Find("GlobalController").GetComponent<GlobalVariables>.player1AssignedController){
  thisTexture = assignedTextureForPlayer; 
 //etc 
 }

However, I'm hopeful there's a better way. All ideas and questions are welcomed! Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by cjdabeast99 · Nov 16, 2021 at 10:13 PM

Solved this issue by using

 PlayerInput.Instantiate(spawnPlayer, controlScheme: "Gamepad", pairWithDevice: Gamepad.all[0]);

Here's what I entered:

 void Awake()
 {
     DontDestroyOnLoad(gameObject);
 }

 private void Update()
 {
     if (SceneManager.GetActiveScene().name != "Menu" && !spawnedCars)
     {
         spawnedCars = true;
         int i = 0;
         while(i < playerCount)
         {
             PlayerInput spawnedCar = PlayerInput.Instantiate(spawnPlayer, controlScheme: "Gamepad", pairWithDevice: Gamepad.all[i]);
             spawnedCar.GetComponent<Car>().myPlayerNum = (i + 1);
             foreach (string getTexture in avaterText)
             {
                 if(getTexture.Contains("P" + (i + 1)))
                 {
                     SetTexture(spawnedCar.gameObject, getTexture, (i + 1));
                 }
             }
             i++;
         }
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cjdabeast99 · Nov 16, 2021 at 10:14 PM 0
Share

Using this I set the player component "Car" to get its assigned player number, automatically spawn the player, and know who's controlling who :)

avatar image cjdabeast99 cjdabeast99 · Nov 16, 2021 at 10:49 PM 0
Share

The only issue I've found with this method is if controller 1 disconnects and controller 2 is setting up the game then technically that controller is player Gamepad.all[1] not 0, but the system will set player 1 still to Gamepad 0 causing controller 2 not to be functional since Player 1 is assigned Gamepad0. So if there's any way to deter$$anonymous$$e what gamepad index is being used that'd be great ;)

avatar image Zombiehunternr1 cjdabeast99 · Apr 26 at 10:43 AM 0
Share

I'm currently try to do a similar thing as you've done, but I don't quite follow how you fixed this issue.

I've got a main menu for people to join the game or leave by making use of the new Player Input Manager. This all works fine, but when I start the game and switch to a different scene I want to instantiate the amount of players that have joined again. The issue I'm facing is that all the amount of players that have joined only work under one controller instead of staying binded to their own controller.

Do you have a good idea on how to fix this issue?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

130 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting up inputs for multiple gamepads/controllers 1 Answer

New Unity Input System Getting continuous input 1 Answer

Oculus Rift controller triggering Gamepad 1 Answer

gamepad controls 1 Answer

Logitech Gamepad F310 button map? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges