Hello,

I'm using Godot 3.5-stable and have the following problem.

I create a custom resource with a GD-script attached. I declare a few export properties in the resource. I need to use those export properties to perform some computations. The problem I've encountered is that inside __init() all the properties have their default values rather than values assigned in the editor and saved in tres file. Also I've noticed that NOTIFICATION_POSTINITIALIZE is never called in resources neither.

Due to that the only thing I've come up with is lazy initialization. I.e. I check if the resource has been initialized in all resource methods as a first line and if not, I call the initialization. It's a little bit dumb way to deal with computations.

Is there a right way to perform computations in resources which use resource export values assigned in the editor.

Thank you!

    z80 Use a setter for your properties.

    When the object is instanced (created) _init() is called. Your values are set after initialization (creation) so that's why you see your default values on _init().

    If you define a setter for your properties you'll know exactly when the previously saved value is set for each one of your properties.

    • z80 replied to this.

      AnidemDex

      Thank you for the reply! Unfortunately I still don't understand how it should help me perform computations using saved export values. I cannot do it inside __init() as when it is called values are still not loaded.

      If I do it in setter, do I recompute everything each time any setter is called? It would be somewhat nonoptimal.

      Is the problem unsolvable?