godotengine / godotengine/godot

Exported Resource assigned by static function in a @tool mode set to <empty> (<null>) by pressing retrieve button.

Open
#110,862 7 comments 0 reactions 0 assignees View on GitHub
bug needs testing topic:editor
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

Reproducible in Godot 4.5

### System information

Windows 11

### Issue description

```
@tool
@export var distribution_curve: Curve = _linear_distribution_curve_constructor()

static func _linear_distribution_curve_constructor() -> Curve:
var curve: Curve
curve = Curve.new()
curve.add_point(Vector2(0.0, 0.0), 0, 0, Curve.TangentMode.TANGENT_LINEAR, Curve.TangentMode.TANGENT_LINEAR)
curve.add_point(Vector2(1.0, 1.0), 0, 0, Curve.TangentMode.TANGENT_LINEAR, Curve.TangentMode.TANGENT_LINEAR)
return curve
```

And it works... I mean - it assigned a Curve constructed by static func when Resource created as scene node's property. But when I click on retrieve button it sets it to null. I tink this behavior is wrong, because I want to get the default value wich I cannot get by any other simple way.

ImageImage

I tried to use saved pre-created Curve resource with necessery parammeters assigned, but I can't make it unique (.new() or .duplicate() or .duplecate_deep() doesn't work for variable declaration even in a `@tool`-script. I think I can imagine some really ugly workarounds using some property changed notification and check if null, or something like that. I neither can't create custom inherited from Curve resource with _init() function, becouse it will be called anywhen I reopen an editor or start the game (and even if it were not so, I already tried and it gives the same issue with retrieve button when I wrote `@export var distribution_curve: Curve = CurveTest.new()`).

### Steps to reproduce

Create a Resource (or any other script) with `@exported` property wich cannot be assigned as small constant expression.

### Minimal reproduction project (MRP)

Minimal project:

```
@tool
extends Resource
class_name SomeTestResource

@export var distribution_curve: Curve = _linear_distribution_curve_constructor()

static func _linear_distribution_curve_constructor() -> Curve:
var curve: Curve
curve = Curve.new()
curve.add_point(Vector2(0.0, 0.0), 0, 0, Curve.TangentMode.TANGENT_LINEAR, Curve.TangentMode.TANGENT_LINEAR)
curve.add_point(Vector2(1.0, 1.0), 0, 0, Curve.TangentMode.TANGENT_LINEAR, Curve.TangentMode.TANGENT_LINEAR)
return curve
```

Contributor guide

Open the contributing guide

Research direction

Use the minimal reproduction code in the issue to reproduce the behavior in Godot 4.5 on Windows 11, then inspect what the editor's retrieve button does for the exported Curve property. Done means retrieving the property restores the Curve produced by the static constructor instead of setting it to null.

Written by the indexing model from the issue text.

Assessment

Domain
game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.