I implemented a GDNative custom Resource to generate procedural geometry, as a child of ArrayMesh. The whole point of my process is to enable the generation of a complex mesh from a few integers, by saving a pseudo-random seed with it. But with the built-in serialization in Godot, the actual Mesh data is serialized too, making the whole thing a bit absurd.. Is there a simple way to avoid serializing a given field in the parent class?
Avoid some parent class's properties serialization
This discussion was caught in the moderation queue since you have not confirmed your account yet.
Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.
(Note: You do not need to repost, the discussion has been moved out and is visible now)
If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile:
I have the same question, my custom Resource is now implemented using GDExtension, and the same behaviour is going on. I'd want to serialize only my resource's fields, not any of its parent's fields. Is there currently a way to do this?
- Edited
When exposing the property in C++, try using PROPERTY_USAGE_EDITOR
as a property usage information as done here (except you should use PROPERTY_USAGE_EDITOR
, not PROPERTY_USAGE_NO_EDITOR
).
The default property usage enables editor display, disk serialization and network serialization. It works as a bitfield – you add values together using the bitwise OR operator.
is the resource running in the editor or at runtime? Also, how is it interacting with the scene? Is it an input to a MeshInstance?
If it's running in the editor, it probably the Mesh
property in a MeshInstance gets saved automatically, or potentially the ArrayMesh itself is saving the data. From what I can tell looking at the source code for the Resource class, it looks like resources are saved automatically thanks to a ResourceCache and there doesn't appear to be a way to stop it or specify what parts you want to save.
What you could try doing potentially is having an exported boolean or something that generates the ArrayMesh so you can see it in the editor, place objects, etc, and then when you set the boolean to false it clears the Mesh
property. Then you could save the scene with an empty Mesh
and it shouldn't then save it to the .tscn
file, but at runtime you could generate the Mesh again. It would be a bit tedious, but that is one way I can think of to work around the issue if the resource is running in the editor.
Thanks for your answer! I just tried this or at least the closest equivalent with the API I have (I'm on the master branch) and it didn't work. The said property is already exposed by the parent, and re-exposing it with my parameters seems to have no effect. My Resource inherits from ArrayMesh, and I'd like to not save the "_surfaces" property with it.
I used the exact same "ADD_PROPERTY" call, removing the PROPERTY_USAGE_NO_EDITOR wich implies PROPERTY_USAGE_STORAGE
I tried re-exposing the property by naming it "surfaces" as it is named in the internal code. I tried ArrayMesh::surfaces, surface, and ArrayMesh::surfaces too.
I use the custom Resource in the editor, as a Mesh property of a MeshInstance3D indeed. Thanks for the workaround idea! I'm still very curious about a clean way. If there is none, I believe it could be of value for Godot. Either a way to manually prevent parent's properties serialization, or simply a Mesh class fit for procedural generation this way.
I don't understand wherein the source code the actual saving is done. Is it "dump"?
@"Papy Chacal" said: I use the custom Resource in the editor, as a Mesh property of a MeshInstance3D indeed. Thanks for the workaround idea! I'm still very curious about a clean way. If there is none, I believe it could be of value for Godot. Either a way to manually prevent parent's properties serialization, or simply a Mesh class fit for procedural generation this way.
Yeah, the workaround isn't the cleanest but it was one of the only ways I could think to work around it right off. Ideally there would be a way to mark variables as non-serializable, and there may be a way, but I'm not aware of it right off.
I don't understand wherein the source code the actual saving is done. Is it "dump"?
I'm not 100% sure, but I think it's the dump
function. It seems it's called somewhere else though, from what I could gather from my quick look through the source.
Thanks, I'll dig around this :)