playMaker

Author Topic: Destroy object can't unload it from memory  (Read 2736 times)

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Destroy object can't unload it from memory
« on: February 25, 2022, 08:36:38 PM »
Hi. My game is an open world game and I need to load and unload objects because otherwise it uses too much of memory. Destroy game objects won't help it can't free up memory. ""Resources Un Load Unused Assets" action can free memory but it makes my game leggy.

Is there any action to unload only one game object from memory and not all unused assets?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Destroy object can't unload it from memory
« Reply #1 on: February 26, 2022, 11:16:24 AM »
Hi.
If these objects are reusable you should look into pooling.

A different way is having a grid scenes system and load/unload scenes

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Re: Destroy object can't unload it from memory
« Reply #2 on: February 26, 2022, 05:23:18 PM »
Hi.
If these objects are reusable you should look into pooling.

A different way is having a grid scenes system and load/unload scenes

No I need to load buildings from resources folder and unload when player is getting far from that building. Resource Load action can load but there is no action to unload that building again.
« Last Edit: February 26, 2022, 05:25:08 PM by Silicon Power »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Destroy object can't unload it from memory
« Reply #3 on: February 26, 2022, 06:11:50 PM »
Hi.
Resources Load (objects) Does the same as Create object, except its getting the reference from the resource folder.

If there are many object that can be reused you might be able to create pools, after you got it from resources load.

But i think loading/unloading scenes (depending on player position) will still be better.

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Re: Destroy object can't unload it from memory
« Reply #4 on: February 26, 2022, 06:23:20 PM »
Hi.
Resources Load (objects) Does the same as Create object, except its getting the reference from the resource folder.

If there are many object that can be reused you might be able to create pools, after you got it from resources load.

But i think loading/unloading scenes (depending on player position) will still be better.

I tried load/unload scene too but even unloading a scene doesn't  free up memory :'( The only action that works is "Resource Un Load Unused Assets" but it makes the game leggy because it unload all unused assets at once.
« Last Edit: February 26, 2022, 06:26:58 PM by Silicon Power »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Destroy object can't unload it from memory
« Reply #5 on: February 26, 2022, 07:15:18 PM »
Hi.
I'll ask to someone i know that uses this system how he handles memory.

Silicon Power

  • Full Member
  • ***
  • Posts: 186
Re: Destroy object can't unload it from memory
« Reply #6 on: February 27, 2022, 03:02:38 PM »
Hi.
I'll ask to someone i know that uses this system how he handles memory.

Awesome thank you a lot.

600

  • Moderator
  • Hero Member
  • *****
  • Posts: 727
    • 600
Re: Destroy object can't unload it from memory
« Reply #7 on: March 24, 2022, 04:36:45 AM »
Hello,

Djaydino pointed me to check this thread.

Indeed there are issues with unloading and using the unload all unused assets made some players experience crashes even when used in unnoticeable spots like during menu loading or similar. Also the frame drops as you mentioned if used on regular basis was not acceptable.
I went for additive scene loading for buildings and it helped for overall experience, still to polish it, but since buildings tend to repeat in areas all do not have to be unloaded.
It may be different on your project, but maybe we could request new action to unload specific asset https://docs.unity3d.com/ScriptReference/Resources.UnloadAsset.html