0 votes

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?

asked Sep 5, 2019 in Engine by goshot (64 points)

1 Answer

+1 vote
Best answer

Could you use _ready instead?

answered Sep 5, 2019 by BraindeadBZH (1,020 points)
selected Sep 18, 2019 by goshot

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

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.

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

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

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.



Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.