Facepunch.Steamworks icon indicating copy to clipboard operation
Facepunch.Steamworks copied to clipboard

Steamworks.SteamInput.Controllers have nothing inside.

Open AvreliyDev opened this issue 3 years ago • 8 comments

so I trying to make it work for 2 days in Unity 2020 I setup game_actions_xxx.vdf file put it in "Steam\controller_config" folder, Steam see it and I setup all bindings in steam controller config / default / big picture mode, etc.

now in code i try to output at least controllers list or one of button signal:

    void Update()
    {
        Steamworks.SteamClient.RunCallbacks();
        Debug.Log(Steamworks.SteamClient.Name);
        foreach ( Steamworks.Controller gpad in Steamworks.SteamInput.Controllers)
        {
            Debug.Log("any controller works");
            gpad.ActivateLayer("testLayer");
            Steamworks.DigitalState KeyValue = gpad.GetDigitalState("Use");
            Debug.Log("KeyValue.Pressed" + KeyValue.Pressed.ToString());
        }
    }

i made a build and receive Client name in "console", and steam overlay works fine, but foreach don`t log anything, because Steamworks.SteamInput.Controllers seems to be empty. Gamepad works in overlay, also try different gamepads (steam official / ps4 dualshock) maybe someone have sample code how to properly make it work?

AvreliyDev avatar Dec 30 '20 09:12 AvreliyDev

Hi!

I've had the same problem for a few days, and nothing I could do made my gamepads detectable.

However when I downgraded the version to 2.2.0 via NuGet, gamepads started to be detected. It seems it broke from 2.2.0 to 2.3.0

KakCAT avatar Feb 21 '21 10:02 KakCAT

I found the solution to the problem; SteamInput has its own initialization process, but it seems that the corresponding Facepunch.Steamworks function in the ISteamInput interface never gets called.

I simply added the following line to ISteamInput ctr right after SetupInterface: Internal.Init();

Then it looks like this:

internal override void InitializeInterface( bool server )
{
     SetInterface( server, new ISteamInput( server ) );
     Internal.Init(); // <- Add this line
}

And then it's possible to detect controllers again.

I don't know if this is the right place of "Internal.Init()". I just tested the funtionallity that way.

I'm sure @garrynewman knows what to do.

BlizzCrafter avatar Feb 21 '21 18:02 BlizzCrafter

Is there an update or resolution for this issue? I'm having the exact same problem with the 2.3.2 release. If there's a quick fix please share, this is one of the only relevant google hits when searching this problem.

Ooseykins avatar Dec 08 '21 07:12 Ooseykins

Ok, the solution is (basically) the same as @sqrMin1 says but today (2021-12-08) the snippet ends up looking like:

internal ISteamInput( bool IsGameServer )
{
	SetupInterface( IsGameServer );
	Init(true);
}

in ISteamInput.cs

I have no idea if Init(true) vs Init(false) makes a difference

If you're completely brainless like me: a handy tutorial describes the build from source process in the first minute of https://www.youtube.com/watch?v=xJl3yHjhils

Ooseykins avatar Dec 08 '21 08:12 Ooseykins

hi! I check my code and trying to remember what is going on....

      SteamInputActive = false;
      foreach (Steamworks.Controller gpREG in Steamworks.SteamInput.Controllers)
      {
          if (!SteamInputActive)
          {
              SteamInputActive = true;//keep alive!
              gpREG.ActivateLayer("controls_scheme");// controls_scheme must be setuped in file
           }
        }

so there wasnt problem in steampunch but it must be properly setupd on steam side... i see i have prepared file "game_actions_XXXXXXX.vdf" where XXXX is my appID on steam... then

in Steam admin website (https://partner.steamgames.com/) appAdmin -> Application -> Steam Input i have my key layouts... im not shure it was uploaded from file or it was generated through interface of steam settings... hope that helps somehow.

i remember it was lot of pain.

AvreliyDev avatar Dec 08 '21 09:12 AvreliyDev

Also running into the issue of no controllers being detected. Has anyone had any luck with Facepunch and SteamInput or is it still broken?

edit: Yep, was definitely my issue (no surpise give https://partner.steamgames.com/doc/api/ISteamInput#Init).

Went ahead and added a public init function to the SteamInput class so I can call it if the game is using steaminput.

...\Facepunch.Steamworks\SteamInput.cs

/// <summary>
/// Must be called when starting use of the ISteamInput interface.
/// </summary>
public static void Init( bool explicitlyCallRunFrame = false )
{
    Internal.Init( explicitlyCallRunFrame );
}

TheWrightDev avatar Jan 21 '22 21:01 TheWrightDev

When is this going to be officially fixed and released so everyone doesn't have to stumble on this old open issue and manually change the code for themselves? Seems like an oversight and looking at the test for it no wonder as it doesn't test anything, no asserts loops which if it is empty still runs without errors.

https://github.com/Facepunch/Facepunch.Steamworks/blob/47b9aca324ca490f7f25ca4e5a2856b31068a698/Facepunch.Steamworks.Test/InputTest.cs

CreepyGnome avatar Mar 17 '22 03:03 CreepyGnome

I was facing the same issue. I solved it and can keep using the NuGet package version by using these two lines:

static void InitSteamInput()
{
    var isteaminput = typeof(SteamClientClass<SteamInput>).GetRuntimeFields().First().GetValue(null);
    isteaminput.GetType().GetRuntimeMethods().Single(m => m.Name == "Init" && !m.GetParameters().Any()).Invoke(isteaminput, null);
}

This calls the Init() method of the internal ISteamInput class using reflection. Just make sure to call this method after calling SteamClient.Init(). Could be useful for others facing this issue and don't want to build from source.

Orongto avatar Jun 17 '22 07:06 Orongto