Hello Guest

Author Topic: Loading and unloading of resources  (Read 6930 times)

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Loading and unloading of resources
« on: February 22, 2012, 02:36:29 am »
I am instantiating animated objects from prefabs, then using Resources.Load() to change the animation.

If I do this in a loop and create 10 objects, is the resource actually loaded 10 times, or just once, and all objects use the same animation?

Do I have to do anything to unload the resource when the scene changes, or will all of the objects being destroyed trigger garbage collection on the animation?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading and unloading of resources
« Reply #1 on: February 22, 2012, 09:27:55 am »
As far as I am aware, the resource is only loaded once. You can verify that by keeping track of memory.

From what I have noticed, when the scene changes, everything gets unloaded, so you won't need to manually keep track of things if you don't need to.

In our titles where we have had to do this, we had to keep track of everything, as we were using it as a customization system. It wasn't really that complicated - we had a singleton class where we requested an animation.

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Loading and unloading of resources
« Reply #2 on: February 22, 2012, 10:21:56 pm »
thanks for that.  I'm still getting familiar with Unity - need to figure out tracking memory usage.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Loading and unloading of resources
« Reply #3 on: February 22, 2012, 10:48:51 pm »
If you have Unity Pro, the profiler is really really useful.

shaz68

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Loading and unloading of resources
« Reply #4 on: February 22, 2012, 11:47:20 pm »
I don't have it yet, but I will down the track.