0 votes

I have a function that creates a new spatial material each time it's called (it's called very often), with another function that 'removes' the material by setting a mesh's surface material to null.

By setting the surface material to null I'm simply 'removing' it from the mesh. BUT, since the material was first created via SpatialMaterial.new() , I'm guessing it still sits in memory? How do you get rid of a material completely (similar to freeing a node)?

in Engine by (506 points)

1 Answer

+1 vote

SpatialMaterial derives from Resource, which derives from Reference. Resources are not free()'d in the same way Nodes are, instead Godot keeps a count of how many references a Material has (how many objects use it). From the docs:

"Unlike Objects, References keep an internal reference counter so that they are automatically released when no longer in use, and only then. References therefore do not need to be freed manually with Object.free."

by (735 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.