Modifying an explicitly declared variable's properties from within an instanced class object

Godot Version

4.3 Stable

Question

How do I modify an explicitly declared variable’s properties from within an instanced class?
For example, consider the following:
get_property_list

I would like to use ResourceSaver to save the variables, ‘name’ and ‘data’, to a .TRES file. However, ResourceSaver will only save @exported variables.

While I can @export ‘name’ because it’s a String, I cannot export Variants. In any case, I’m not trying to edit the contents of these variables in the editor. I’m trying to store them to an external file.

So I want to modify the ‘usage’ property of these variables to be PROPERTY_USAGE_STORAGE.

I have referred to the documentation, however it only seems possible to append new properties and not edit existing ones. Or rather, if there is a way to override the _set(), _get(), and _get_property_list() methods to achieve this I have not figured out how.

Any insight into this matter would be greatly appreciated!

Have you tried _validate_property()?
Here’s a relevant post that might help.

1 Like

Ahah, I feel so silly!

I spent so long staring at the _get(), _set(), and _get_property_list() documentation when I was looking in the wrong place the entire time. Tbf, I got thrown off by statements like this:


I thought, I’m customizing properties, so this must be what I need.

In any case, if someone reading this happens to have a similar issue to me, it may be useful to know that _validate_property() is automatically called by the engine at some point (seemingly) between compile time and runtime, so you just need to override the method and you can safely assume it will be called at the latest when the object is being instanced.

Thanks for the help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.