Probably this is done through exposing the property using the _get_property_list function rather than the export keyword. Then you can dynamically set the hint text using conditions or variables, giving more dynamic functionality than you can get using just export
. You also have to write _set
and _get
functions though, as properties exposed through get_property_list
expect them in order to work.
It can kinda be a pain and results in a good amount of boiler plate code, but then you can also use groups, which is another added bonus! This is how I have the inspector properties setup for Twisted IK 2 and it makes the inspector nice and dynamic.
Here’s an example! I wrote it off memory, but I think it should work:
var example_float = 10.0
var example_array = [1, 2, 3]
var example_array_index = 0
func _get_property_list():
# get the base properties, as otherwise default Godot
# node properties will not work.
var properties = .get_property_list()
properties.append({
“name”:”example_float”,
“type”:TYPE_REAL,
});
# A slightly more complicated example
var property_enum_string = “”
for i in range(0, example_array.size():
if i == example_array.size()-1:
# Do not add a comma
property_enum_string += str(example_array[i])
else:
# Add a comma
property_enum_string += str(example_array[i]) + “,”
# add the property
properties.append({
“name”:”stuff/group”,
“type”:TYPE_INT,
“hint”:PROPERTY_HINT_ENUM,
“hint_string”:property_enum_string
})
# make sure to return it! Otherwise it will not work
Return properties
func _get(property_name):
if (property_name == “example_float”):
return example_float
elif (property_name == “stuff/group”):
return example_array_index
else:
# Needed so normal node properties work, I think.
# This could also cause a crash, so remove this if you get crashing!
# If this causes crashing, then return null and it should work
return ._get(property_name)
func _set(property_name, property_value):
if (property_name == “cool_float”):
# not sure if you need to cast in GDScript, but its required in C#
example_float = float(property_value)
# always return true if you set a value
return true
elif (property_name == “stuff/group”):
example_array_index = int(property_value)
return true
else:
# Needed so normal properties work, I think.
# Like before, this could cause crashing! I don’t remember right off.
# if this causes crashing, then just return false and it should work
return .set(property_name, property_value)