Skip to content

Can't use VARIANT_ENUM_CAST with enum class #1917

Closed

Description

@NoctemCat

Godot version

4.5.1.stable.mono

godot-cpp version

godot-4.5-stable

System information

Godot v4.5.1.stable.mono unknown - EndeavourOS #1 SMP PREEMPT_DYNAMIC Sun, 11 Jan 2026 17:10:53 +0000 on X11 - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1650 (nvidia; 590.48.01) - Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz (8 threads) - 15.49 GiB memory

Issue description

VARIANT_ENUM_CAST doesn't work with enum class, looks like you need to change p_val to static_cast<int64_t>(p_val) in PtrToArg<m_enum>::encode.

VARIANT_ENUM_CAST does work in Godot itself with enum classes.

Also I guess VARIANT_BITFIELD_CAST is the same, and the master still has the same code, so it looks like the issue is still exist

Steps to reproduce

Use VARIANT_ENUM_CAST with enum class

Minimal reproduction project

N/A

Activity

  1. dsnopek commented on Jan 31, 2026

    @dsnopek
    Collaborator

    VARIANT_ENUM_CAST does work in Godot itself with enum classes.

    Are you sure this is true?

    There was a relatively recent PR where an attempt was made to add support for binding enum classes, but it ended up getting closed because it turned out to be trickier to implement than expected

  2. added
    enhancement
    on Jan 31, 2026
  3. NoctemCat commented on Feb 1, 2026

    @NoctemCat
    Author
    Image

    EulerOrder, HatDir, HatMask, JoyAxis, JoyButton, MIDIMessage, MouseButton, MouseButtonMask, Key, KeyModifierMask, KeyLocation are all enum classes, and they are just from core/variant/binder_common.h alone, maybe there are more in some other places.

    Also I meant the actual VARIANT_ENUM_CAST, not BIND_ENUM_CONSTANT. Found kind of relevant issue #1620 , since those enums are defined as enum classes inside the engine and are already used, VARIANT_ENUM_CAST should have already worked even then

  4. NoctemCat commented on Feb 1, 2026

    @NoctemCat
    Author

    Like, sure, don't add support for BIND_ENUM_CONSTANT enum classes as it is not in engine itself, but VARIANT_ENUM_CAST should already work as it does in the engine, and we would then use some custom ClassDB::bind_integer_constant and be on our own

  5. dsnopek commented on Feb 1, 2026

    @dsnopek
    Collaborator

    Ok, I think you're right that VARIANT_ENUM_CAST() does work with enum classes in Godot, and I think it's this code that does it:

    https://github.com/godotengine/godot/blob/98782b6c8c9cabe0fb7c80bc62640735ecb076d3/core/variant/method_ptrcall.h#L243-L246

    PR #1914 should fix this

  6. NoctemCat commented on Feb 20, 2026

    @NoctemCat
    Author

    Seeing as PR got merged closing issue as completed

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions