In my Evergine UWP project I have 100s of prefabs created, all with materials and some with textures. I pick from a dropdown in my UWP project a prefab to be loaded into the scene. When I select a different prefab from the dropdown the previous loaded prefab/entity is unloaded and the newly selected prefab is instantiated and loaded. My issue is that if I continue loading new prefabs that has not been loaded before the RAM usage continues to climb. So the previous entity is not fully removed and I'd like to know how to remove it and clear the resources it used.
This is how I load the prefab and add it to the scene: The Preview.Key is from the bound is for me to be able to remove it later.
var prefab = AssetsService.Load<Prefab>(Preview.Key, true);var entity = prefab.Instantiate();
Hello all.
In my Evergine UWP project I have 100s of prefabs created, all with materials and some with textures. I pick from a dropdown in my UWP project a prefab to be loaded into the scene. When I select a different prefab from the dropdown the previous loaded prefab/entity is unloaded and the newly selected prefab is instantiated and loaded. My issue is that if I continue loading new prefabs that has not been loaded before the RAM usage continues to climb. So the previous entity is not fully removed and I'd like to know how to remove it and clear the resources it used.
This is how I load the prefab and add it to the scene: The Preview.Key is from the bound is for me to be able to remove it later.
var prefab = AssetsService.Load<Prefab>(Preview.Key, true);
var entity = prefab.Instantiate();
entity.Tag = Preview.Key.ToString();
Scene.Managers.EntityManager.Add(entity);
This is how I remove the entity:
var entity = Scene.Managers.EntityManager.AllEntities.Where((x) => x.Tag == Preview.Key.ToString()).FirstOrDefault();
Scene.Managers.EntityManager.Detach(entity);
Scene.Managers.EntityManager.Remove(entity);
entity.Destroy();
But at this point, if I had gone through the process 30 times, the RAM usage is at 2.8gb and not going down at all.
I tried adding this when removing the entity:
entity.FindComponent<MeshComponent>().Model.Dispose();
And this:
AssetsService.Unload(entity.FindComponent<MeshComponent>().Model.Id);
AssetsService.Unload(Preview.Key);
But no luck.