Hello! The game I am working on involves the generation of a lot of procedural assets. I need these assets to be present in the Editor, because I need to see them to work on them in various ways. However, I do not want some of the Resources I create to be serialized into the scene. I would prefer that they always be generated on the fly.
I am struggling with a way to make this work. I have tried a few things:
All procedural-generated Resources must not be attached to any "owned’ nodes in the scene. This works, but it greatly reduces my ability to see what I am working on, as the nodes/resources are not visible in the scene tree.
When generating resources, save them into a “cache” folder, so that they are at least serialized in binary form. Then, ignore these files in .gitignore and overwrite them whenever the Resource is regenerated. This does not work because if the cached resources are deleted, then the scenes will fail to open due to missing Resources. I wish that in this case the Resources could simply be cleared.
Anyone have any advice on this type of issue? Thank you!
If a resource has a “resource_path” property, that’s where it will be saved. If there is no such property, it may not save. I say “may not” because, honestly, resources are pretty buggy atm.
If you want stuff available in the editor, then you need to use @tool (in gdscript, at least) in your scripts. This way they run in the editor (as well as runtime). You could then control the life and death of resources by way of code.
One more question - Do you know of a way to do this in Resource scripts, to free up sub-resources? I see that this particular notification seems to be only for Nodes, and I don’t see that Resources have any notifications at all.
If you mean having some properties in the inspector that you don’t want to be serialized to disk then you can use Object._get_property_list() to control what gets serialized to disk and what not.
I see, that’s useful! Maybe what I’m doing here is an unusual case. Here’s some pseudocode to explain. Let’s pretend for example that this resource generates an image somehow in some way not handled by the standard image loaders.
In this case, the “Image” resource will be serialized into the scene, because this WeirdTexture is attached to a mesh in the scene. Maybe this is unexpected behavior, but it’s what I’ve observed.
I ended up handling this differently, but was curious if this could work somehow.