hi
with new input system i can detect game pads , but first button pressed gamepad become Player1 and another become Player 2 , but when i switch my scene to another scene , this process repeated but if player2 press gamepad button before player 1 , this time player 2 detected as player 1 in new scene.
is there any way to detect gamepads from each other or transfer player input manager settings to another scene or any other solution?
Consider the function DontDestroyOnLoad(Object)
Unity - Scripting API: Object.DontDestroyOnLoad
This function makes it so an object isn’t destroyed when you enter into another Scene. However, if two scenes have a PlayerInputManager
script, you will now have 2 in your scene, which will likely cause problems for you. The solution to this is the Singleton Pattern.
private static PlayerInputManager singleton; //note the 'static' keyword. means "shared by all instances"
private void Start()
{
if (singleton == null) //we are the first one
singleton = this;
else //we are a duplicate
Destroy(this); //there is only a single instance allowed.
}