Hello,
I’m using unity iphone basic and I’m wondering how unity does load things
I will ask the question based on a simple example:
I have an empty scene except one gameobject with the following script
var bigIMG : Texture;
Awake(){}
There is a big image connected with the bigIMG var in unity
so what of the 3 following situations is true?
the line represents some kind of stylized “memory used”
The Unity Documents say “Awake is called after all objects are initialized so you can safely speak to other objects or query them”
(Unity - Scripting API: MonoBehaviour.Awake())
But when does the loading process start and when does it end?
When is the bigimg - texture complete loaded into memory?
When I want to avoid that the system loads unused data… can I unset the vars in the awake function like
Awake(){
bigIMG = null;
}
or do I have to delete them from the gameobject in the editor?
I’m not sure, rollin, I’m currently fixin’ to learn how prefabs affect memory. It appears that unity’s options for managing the amount of memory you’re using are rather limited.
I do think that your question will really boil down to how textures initialize, however. As soon as you’ve instantiated an instance of your script, your texture is going to initialize. I can tell you for certain that the constructor fires before Awake, but that Awake finishes executing before control flow is returned to the instantiating entity.
This is probably not recommended, but if you need to do something functional without side effects, you can probably get away with it in the constructor if you do something like:
C#
public MyObject() : base()
{
sideEffectFreeAction();
}
How texture’s internal caching works, I have no earthly idea, but if I understand my C# right, the constructor should fire before instance variables are initialized. If you need side-effects you may be screwed.
Sorry I couldn’t be more help.
thx tm, that’s some interesting information.
Seems I was able to increase loading times a bit. (more then 50% in my case)
Even though this might not be the best solution it is at least a simple way of getting rid of unused data before it loads to its full extends.
It depends on the amount of data that unity loads from initialization to the moment Awake() gets called.
If anyone has some more insight and / or solutions this would be very appreciated