Freeing Unity Textures and Meshes After Transfer to RealityKit

I’m using the glTFast package to import models at runtime. Textures and meshes are marked as readable on import to enable transfer from Unity to RealityKit. However, due to limited memory, I don’t want to keep them loaded indefinitely. Is there a way to release these assets from the memory once they’ve been transferred to RealityKit?

Basically, no, although I think this is something we would like to add. I would suggest submitting it to our road map, though I will also create an internal ticket to track the request. We’re planning to make some changes to transfer meshes and textures via GPU blit through LowLevelMesh/LowLevelTexture, and I think that adding a way to indicate that the Unity objects won’t be needed after transfer would be a good add-on to that.

You could try calling Mesh.UploadMeshData(true)/Texture2D.Apply(false, true) to remove the CPU copy at some point after transferring it (that is, waiting at least one frame so that the data is actually transferred to RealityKit first), but that would only remove the CPU copy (and potentially create a new, unnecessary GPU copy), and it wouldn’t work if the data needs to be retransmitted (e.g., the model is removed and then readded later), so I think it would be difficult to make it work correctly.

Thanks for the detailed explanation! I’ve submitted a roadmap ticket.

In the meantime, I’ll try a workaround by marking the meshes/textures as non-readable after a few frames as you suggest, but I’d prefer a proper memory management solution.