- Home /
how to transfer player input manager setting to another scene?
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?
Answer by Monsoonexe · May 04 at 12:39 AM
Consider the function DontDestroyOnLoad(Object)
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
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.
}
Your answer
Follow this Question
Related Questions
Xbox controller not working on mac build 1 Answer
Unity not recognizing Saitek p880 gamepad? 1 Answer
New input sytem not working on build 1 Answer
Controller navigation of UI 1 Answer
Mapping multiple controllers 1 Answer