I have about 50 billboards in my level, each of them fully loaded of hi-res textures that I load runtime with the Import File As Texture2D node.
All 50 actors mut be present in the level, they’re not procedurally spawned but carefully composed by me.
You can only see one or two of them simultaneously, so my idea is to create its dynamic material with the hi-res textures on demand, just before becoming visible. And then, once I’m done with that billboard and go for next one, its dynamic material and texture is deleted, releasing free memory for the others.
The idea is not working. I can not find a way to get rid of them once assigned.
I’ve tried to set the BP Hidden in game or not visible. No memory released.
Also tried assigning the BP a new basic mateial with no texture, to be sure the one I want to delete is no longer referenced by the BP.
Anyone knows if this is possible wtih Blueprint on runtime? Force the engine to get rid of an unused dynamic material or it texture.
I didn’t mention but, yes, I’m testing packaged prototypes. Good point.
It’s weird. After assigning all actors a new non-textured plain material, all the created dynamic materials and its imported textures are, for sure, un.referenced. But still in memory.
Maybe the engine will take some time before discarding them. Or maybe Engine will not get rid of them until it needs to load something else?
That’s what I was looking for! Or, at least, looks like that. 'ill test it this evening. I hope it works!
I’ll also test with sequential load/deletes, and see what happens if I am constantly loading and unloading textures in a loop, instead of the test I’m doing now: deleting them all at once and wait for the memory to recover.
I still need to figure out if a simple HIdden in Game or Visibility off would eventually unload the textures, of if I really do need to break all the references by assigning a new basic material. But that’s something I can easily test, and not a big issue if it works.
For anyone that could find this useful, this is what I’ve found with some quick tests:
Once the materias is unreferenced, the engine will delete it eventually.
If you keep completely idle, no movements and no actions, it will be deleted within 30 secs. (I was not waiting enough on my tests this morning).
If you load a new texture (or anything, I guess), then unreferenced garbage is erased inmediately.
Also, if you need to, you can force the unload with that node “Collect Garbage” at any moment you want, without waiting for the “auto garbage collect cycle” of the engine.
And no, making an actor HIdden in Game, or not Visible, is not enough. You need to leave the material you want to get rid of completely un-referenced. Destroying the actor or the component could work, but I can not do that in this project.
I’ve found no specific node to delete a material from an actor, but assigning a new empty one does the job with a single node, so it’s ok for me.