Skip to content

Gamepad information functions don't work before Ebiten loop starts #3258

@SolarLune

Description

@SolarLune

Ebitengine Version

v2.8.8

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

Go Version (go version)

1.24.3

What steps will reproduce the problem?

Try polling for gamepad information (e.g. ebiten.GamepadName() before calling ebiten.RunGame(). The functions will return blank / false information, even if the gamepad is recognized and supported. For example, consider this example code:

package main

import (
	_ "embed"
	"fmt"

	"github.com/hajimehoshi/ebiten/v2"
)

type Game struct {}

var gamepadID ebiten.GamepadID = 1

func (g *Game) Update() error {

	fmt.Println("From update:", ebiten.GamepadName(gamepadID))

	return nil
}

func (g *Game) Draw(screen *ebiten.Image) {}

func (g *Game) Layout(w, h int) (int, int) { return w, h }

func main() {

	fmt.Println("At start:", ebiten.GamepadName(gamepadID))

	if err := ebiten.RunGame(&Game{}); err != nil {
		panic(err)
	}
}

On my machine this outputs:

At start: 
From update: 8BitDo Ultimate Wireless
From update: 8BitDo Ultimate Wireless
From update: 8BitDo Ultimate Wireless
From update: 8BitDo Ultimate Wireless
.....

I can understand if it doesn't work beforehand, but it would be nice to update the documentation to account for this.

What is the expected result?

Either at least some gamepad functions (e.g. informational ones) should work before calling ebiten.RunGame(), or gamepad functions should have their documentation updated to indicate that they won't work properly until Ebitengine has been initialized.

What happens instead?

Gamepad functions like ebiten.GamepadName() or ebiten.IsStandardGamepadLayoutAvailable() return blank or false information, even if a supported gamepad is connected.

Anything else you feel useful to add?

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions