How to get access to Inspector-set Resource variables during _init?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By goshot

Script simplified to illustrate problem of state at _init:

extends Resource

export(int) var i

func _init():
    var x = 0 + i

x is always 0 even if i is set to a value other than 0 in the Inspector pane of the editor for that resource. How do we get the set value during initialization of the resource?

:bust_in_silhouette: Reply From: BraindeadBZH

Could you use _ready instead?

This is a resource (extends Resource), not a node.

goshot | 2019-09-05 18:54

Ha yes, did not saw that. It seems there is no hook for when the resource is loaded. What I would do is to define a setter for my export.

BraindeadBZH | 2019-09-05 19:02

Would a setter function for the exported property be called if the value is set in the Inspector?

goshot | 2019-09-06 17:12

Yes it should, but only if you declare the script as a tool.

BraindeadBZH | 2019-09-06 17:15

This could work. I think the suggestion here is doing the work in a node script setget set or property set intercept function. Ideally, this would be part of the code of the Resource, not of a node script, but I’m going to accept this as the best solution we know.


How to get function called when text changed in Inspector for a tool node/script that extends Label? - Archive - Godot Forum

goshot | 2019-09-18 18:00