Player Input Manager: How get the PlayerInput object that was just spawned?
I have my Player Input Manager's Notification Behavior set to "Invoke Unity Events". I assigned a script and method to Player Joined Event, called onPlayerJoined. This event fires when a new input device presses a button, but I need to get that Input Device instance from within the onPlayerJoined method. How do I do this? I tried adding a PlayerInput parameter to the method, but it comes back as null. What am I doing wrong? Or, what is the proper way to add a parameter to this event?
Answer by dubbist · Feb 03 at 10:49 AM
I had a similar problem, setting up the save rebinding, which also references the PlayerInput object.
simply, on your player object
> Add Component > Player Input
plug your PlayerInputActions into the Actions
then set up the reference in your script
PlayerInput playerInput; void Start() { playerInput = GetComponent<PlayerInput>(); } void SaveUserRebinds() { var rebinds = playerInput.actions.SaveBindingOverridesAsJson(); PlayerPrefs.SetString("rebinds",rebinds); }
I think I may have deleted the PlayerInput component after I generated the C# PlayerInputActions Class??