Hertzole / gold-player

A first person player controller for Unity.
MIT License
160 stars 16 forks source link

Trying to use Gold Player with the old input system. #32

Closed Kry-a closed 4 years ago

Kry-a commented 4 years ago

Using a standard setup on Linux Kubuntu by having the Gold Player Controller and Gold Player Input in the gameobject. I don't have the new input system package installed, neither i have it enabled in the project settings. I have 1 error which is:

KeyNotFoundException: The given key was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <437ba245d8404784b9fbab9b439ac908>:0)
Hertzole.GoldPlayer.GoldPlayerInput.GetAxisRaw (System.String axisName) (at Assets/Hertzole/Gold Player/Scripts/Core/GoldPlayerInput.cs:127)
Hertzole.GoldPlayer.PlayerModule.GetAxisRaw (System.String axisName) (at Assets/Hertzole/Gold Player/Scripts/Core/Modules/PlayerModule.cs:130)
Hertzole.GoldPlayer.Core.PlayerMovement.GetInput () (at Assets/Hertzole/Gold Player/Scripts/Core/Modules/PlayerMovement.cs:400)
Hertzole.GoldPlayer.Core.PlayerMovement.OnUpdate (System.Single deltaTime) (at Assets/Hertzole/Gold Player/Scripts/Core/Modules/PlayerMovement.cs:439)
Hertzole.GoldPlayer.GoldPlayerController.Update () (at Assets/Hertzole/Gold Player/Scripts/Core/GoldPlayerController.cs:126)

In the GetAxisRaw I looked at what string is being used as the axis, it's "Player/Horizontal".

And Use Key Codes is true.

Version Info: Unity: 2020.1.0a13.1443 Gold Player: 1.4

Hertzole commented 4 years ago

If I'm not mistaken you should be getting a warning message saying "GoldPlayerController.ActionMap is useless when not using the new Input System." This will be fixed in the next version but for now, there's a simple fix you can do yourself. In the PlayerModule class, on line 44, there should be a piece of code like this:

if (player != null)
{
    rootActionMap = player.ActionMap;
}

Simply put #if ENABLE_INPUT_SYSTEM && UNITY_2019_3_OR_NEWER around it, like this.

#if ENABLE_INPUT_SYSTEM && UNITY_2019_3_OR_NEWER
if (player != null)
{
    rootActionMap = player.ActionMap;
}
#endif

(and for good measure, since Unity will complain otherwise, just set rootActionMap at the top to an empty string private string rootActionMap = "";)

Kry-a commented 4 years ago

Alrighty, everything's working now. Thank you :D

Hertzole commented 4 years ago

Issue has been fixed in https://github.com/Hertzole/gold-player/commit/b5c026a4bd04e3afa589e66a2036e1bc5e383f9c