-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Exporting an enum sourced from a Resource doesn't work. #79412
Labels
Milestone
Comments
I have a solution for you until this is fixed (It's not pretty, but it works). @tool
extends Node3D
const Constants = preload( "res://constants.tres" )
const Direction = Constants.Direction
var direction : int
func _get_property_list() -> Array:
var properties = []
properties.append({
&'name': &'direction',
&'type': TYPE_INT,
&'hint': PROPERTY_HINT_ENUM,
&'hint_string': ','.join(Direction.keys())
})
return properties |
Testing: const Constants = preload("res://constants.gd")
const Direction = Constants.Direction
@export var direction := Direction.SOUTH
const Constants = preload("res://constants.tres")
const Direction = Constants.Direction
@export var direction := Direction.SOUTH
godot/modules/gdscript/gdscript_analyzer.cpp Lines 3988 to 3997 in a758388
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Godot version
4.1.stable
System information
Godot v4.1.stable - Windows 10.0.22621 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 3070 Laptop GPU (NVIDIA; 31.0.15.3141) - Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz (16 Threads)
Issue description
Loading constants from a resource should work fine. This is something I do in older versions (pre-3.0) since constants seem to still be only directly accessible by other scripts if they're part of an instance, otherwise I'd have to be calling static functions to get the constant values (yuck!). Even in 4.1, it's useful so that exported values can be tweaked from the inspector while still being treated as constants.
In this case, the issue came up because the plugin I'm writing is configured this way. Upon entering the tree, it ensures the configuration resources exist. An alternative might be to auto-generate a script extending the script containing the constants and overriding the values in the
_init
function, but there shouldn't be an issue with going through the Resource.The only issue I've encountered is that exporting an enum doesn't work this way, it just shows a SpinBox as if I exported an integer. Loading the script just to get the enums while using the resource for everything else works, but it's not ideal.
Tiny update:
I tried assigning the type of
direction
more explicitly like this:@export var direction: Constants.Direction = Constants.Direction.SOUTH
And got these errors:
Parse Error: "Constants" is a constant but does not contain a type.
Parse Error: Cannot use simple "@export" annotation because the type of the initialized value can't be inferred.
Steps to reproduce
Write a script named
constants.gd
containing the following code:Create a new Resource named
constants.tres
, and assign this script to it.Create a scene with a script associated, something like
character.gd
.Copy this code to it:
In the inspector, it should show an OptionButton with all the enum values, but instead, you'll only see "3".
Minimal reproduction project
N/A
The text was updated successfully, but these errors were encountered: