playMaker

Author Topic: Load/Unload Resources  (Read 3868 times)

devis.rossini

  • Playmaker Newbie
  • *
  • Posts: 18
Load/Unload Resources
« on: July 15, 2015, 11:05:28 AM »
Hi,

In my game I need to load a specific resource asap, when a level is loaded.
At the moment I have a "main" FSM, that load that resource in its start state.
After that, it broadcasts an event to the others FSMs in order to start their flow.

I want to unload the resource loaded previously when the main FSM is destroyed, but how can I do?

Thanks a lot,

Devis

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Load/Unload Resources
« Reply #1 on: July 15, 2015, 11:42:35 AM »
Hi,

 to unload resources, you'll have to use a custom action UnloadUnusedAssets available on the Ecosystem

but be careful it's creating hickups.

typically, if you want to clear resources usage, the best way is to load a new scene, and during that process force an unload. this is especially true on mobile, where I even have a totally empty scene with just a playmaker fsm loading the actual scene, this way I found it properly clean up memory and unused assets, else they persists and you get memory leaks.

Bye,

 Jean

devis.rossini

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Load/Unload Resources
« Reply #2 on: July 15, 2015, 11:48:45 AM »
Yes, it's true, but I need to manually handle a specific resource type, that is a sort of prefab catalog.

So, when I enter a level, I must load a specific catalog and, when I load the next scene, unload that catalog and load a new one.

How can I execute actions when an FSM is disabled or destroyed?

Thanks a lot,

Devis

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Load/Unload Resources
« Reply #3 on: July 15, 2015, 12:35:43 PM »
Hi,

 destroying a GameObject is the only thing you can do then, and call unload asset everytime you load a new catalog, there isn't much Unity will provide if you can't reload levels.

also, depending on the content, you may be better off to not destroy and simply disable, so that next time that catalog is loaded it's instant.

and also, I would suggest checking if you can't combine some of the items into generic ones, and depending on the catalog would change their images, sprite or mesh/material ro reflect a specific item. this is a very powerful approach too.


Bye,

 Jean

devis.rossini

  • Playmaker Newbie
  • *
  • Posts: 18
Re: Load/Unload Resources
« Reply #4 on: July 18, 2015, 07:06:22 AM »
Ok, thanks.

Why the FSMs don't have an event for MonoBehaviour's Awake(), OnEnable(), OnDestroy(), etc? In particular, OnDestroy would be very useful.

I'm curious :)

Devis
« Last Edit: July 18, 2015, 10:02:23 AM by devis.rossini »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Load/Unload Resources
« Reply #5 on: July 20, 2015, 06:18:48 AM »
Hi,

 it's a good question. I am not sure myself, maybe for reasons that it doesn't fit the principles behind an Fsm logic. But I agree it would be useful.

Bye,

 Jean