Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_axis() expects a non-existing Enum Vector3.Axis #99309

Closed
Sithoid opened this issue Nov 16, 2024 · 2 comments · Fixed by #99424
Closed

set_axis() expects a non-existing Enum Vector3.Axis #99309

Sithoid opened this issue Nov 16, 2024 · 2 comments · Fixed by #99424
Assignees
Milestone

Comments

@Sithoid
Copy link

Sithoid commented Nov 16, 2024

Tested versions

Reproducible in: Godot 4.3

System information

Godot v4.3.stable - Windows 10.0.19045 - GLES3 (Compatibility) - NVIDIA GeForce RTX 3050 Ti Laptop GPU (NVIDIA; 31.0.15.2799) - AMD Ryzen 5 5600H with Radeon Graphics (12 Threads)

Issue description

According to the docs, the set_axis() function of the SpriteBase3D node expects a "Vector3.Axis" enum. The link to that enum is active in the in-engine docs, but not in the web docs. If you navigate to the Vector3 docs, you'll see that an Axis enum doesn't exist, only three separate constants.

This would be just a documentation issue, but the result is that there is no valid enum that set_axis() would accept, and I believe having to use an int there would be bad practice. Moreover, the editor's behavior here depends on how the Sprite in question is referenced, which is the most confusing part for me:

$Sprite3D.set_axis(Vector3.AXIS_Y) # This works

@onready var sprite : Sprite3D = $Sprite3D # Explicit casting as Sprite3D is what seems to be causing the error
# in any function, i.e. _ready():
sprite.set_axis(Vector3.AXIS_Y) # This triggers warnings

The warnings this latter example triggers are as follows:

W 0:00:04:0562   Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
  <GDScript Error>INT_AS_ENUM_WITHOUT_CAST
  <GDScript Source>node_3d.gd:7
W 0:00:04:0563   Cannot pass 1 as Enum "Axis": no enum member has matching value.
  <GDScript Error>INT_AS_ENUM_WITHOUT_MATCH
  <GDScript Source>node_3d.gd:7

I believe that at the very least the Sprite3D docs should be modified to reflect the intended use, but ideally set_axis() should accept existing enums (whether it means reimplementing Vector3.Axis or making it understand the AXIS constants) without warnings.

Steps to reproduce

See the MRP. To reproduce it yourself:

  • Set up a 3D scene.
  • Create a Sprite3D and cast it as Sprite3D in the script.
  • Address the resulting variable in the script with set_axis(). The prompt will suggest using the Vector3.Axis enum. Type "Vector3" and choose any AXIS const (AXIS_X, AXIS_Y, AXIS_Z) from the prompt.
  • Run the scene and see the warnings.

Minimal reproduction project (MRP)

axis-test.zip

@Mickeon
Copy link
Contributor

Mickeon commented Nov 16, 2024

CC @dalexeev

@PhairZ
Copy link
Contributor

PhairZ commented Nov 16, 2024

I'm Working on a PR to fix this.

I looked at other implementations for other classes like Vector4 and Vector2. None of them had that issue, instead they treated Vector2.Axis params and return types as an int. At least for binded methods. So I'll change any binded method that uses Vector3.Axis as param/return type to int. This will most definitely break compat, but I'll have a shot at it.

Maybe later someone can follow this PR with a PR that changes all VectorX.Axis param types to int for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment