#Accessing a Resource after setting its @exports in C#
1 messages · Page 1 of 1 (latest)
_ready()?
Resources do not call _ready()
Ah right, forgot.. my bad.
Then create a new function in the Resource (setup() or whatever), and on the node/script that you load the resource, put that setup() into the local _ready()?
The resource is used by a wide variety of objects, i can't guarantee any given object will know what to call on the Resource or at the right time, it would quickly become unmaintainable.
I think there really is no self contained solution.
Make all those objects inherit from the same class, and the base class would have the _ready() with setup() inside? 🤷♂️
Otherwise maybe a getter could work? So that when a var is read, it would execute whatever extra steps that are needed.
What about setters or getters on the variables? Does c# have those?
I can't, i have objects that range from a map editor, to the ability to serialize it and send it over a network. They can't inherit each other.
It does, and i was trying them. But i am not sure in what order they get called (and i can't just perform the update for every property, it involved random generation and it is fairly expensive)
But i'll see what order does _set() print in.
Update: it doesn't get called at all for some reason
I was trying to change the values from the editor, still no prints.
I'll just make a git issue about it
Did you make it a tool script?
yep
Everything is running fine, even the function i was talking about (atm i have a Tool Node set to run it)
But there are no prints
I've just accepted there's no solution. Now here's to hope they eventually implement something to solve this.
I'm starting to guess that since it requires to do those extra operations maybe it shouldn't be a resource but a scene?
One approach I've used in the past to handle this limitation is to implement lazy initialization of the Resource.
Basically, you set up a method such as:
public void UpdateIfDirty()
{
if (IsDirty)
{
IsDirty = false;
// Do your initialization.
}
}
Then call that method in the top of any method/property getter dependent on the initialized data.