godotengine / godotengine/godot

Can't override `_to_string` of `InputEventAction`

Open
#110,338 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

discussion topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

Tested versions

4.4.1, 4.5

System information

Linux

Issue description

Can't override _to_string of InputEventAction because the to_string is already override in Godot source code:
https://github.com/godotengine/godot/blob/2dd26a027a99633231184616d4dd287bbdd1c0a3/core/input/input_event.h#L496
https://github.com/godotengine/godot/blob/2dd26a027a99633231184616d4dd287bbdd1c0a3/core/input/input_event.cpp#L1657-L1660

This issue exists in both gdscript and gdextension.

Steps to reproduce
extends Node2D

class InputEventA extends InputEventAction:
	func _to_string() -> String:
		return "A"

func _ready() -> void:
	print(self.to_string())
	var a := InputEventA.new()
	print(a.to_string())

func _to_string() -> String:
	return "This Node"

This prints:

This Node
InputEventAction: action="", pressed=false

Minimal reproduction project (MRP)

N/A

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with core/input/input_event.h around line 496 and core/input/input_event.cpp around lines 1657-1660, then reproduce the behavior with the GDScript example from the issue. Check how InputEventAction string conversion interacts with subclass overrides in GDScript and GDExtension; done means the override is honored in both cases and the behavior is covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.