Scripts, variables, and memory.

Hello again everyone. Well although im not totally newbish to Unity, theres still a lot of things i need to learn and one of the things i have not been able to determine, is exactly how performance and memory are affected by scripts and refernces to assets. Heres what i mean.

Assuming i create a Titlescreen script, and in this script is all the variables with things like the titlescreen background image, the mainMenu and all the images associated with it, buttons etc. Now all these variables are assigned their data through the inspector, and during game start up, the titlescreen does it thing, ya dada , you join into the game, and thats it. At this point , a boolean value is assigned saying that TITLESCREEN is no longer true, and the GUI methods stop drawing from this script. In short, does the memory still take a hit, from all these variables being assigned to, even though they are no longer being used in the forefront.

The script is still active , just not drawing anything. If they are still causing memory useage, what would be recommendations for correcting this… OR, is this method fine ?

Im reaching a stage where my own critique of my own project code is hindering me greatly, because im unsure if my methods are just crap, and maybe im lacking a few peices of knowledge in general that would help out,. Anyways, thanks for reading and answers.

~Will

Variables still referenced (like class properties/fields) will use memory even when not used for any calculations, eg.

Temporary variables created and used inside of your function will not take up any memory when not used. So you will be fine.

Ok, continuing on, is another things about scripts and variables i have noticed. Lately i have been tring to use scripts that are not attached before runtime, but instead are added using AddComponent @ runtime when needed. Couple things have bothered me and i dont really understand whats goin on here.

In unity i create a script (its using monobehaviour) and i notice that certain variables are exposed in the inspector. Most obviously is Texture referencing variables. You can even assign the texture to the script even though its atttached to nothing in the inspector. The thing that bothers me is, that when @ runtime i add the component, the previously assigned to texture, comes back as null. Why would it loose its reference?

Not sure if i did a good job explaining, if not say so, i wil try and elaborate.

You mean you can fill the properties of the script, even when this script is not assigned to any gameObject? Didnt know this was possible.

The only way I thought exists to assign default values to this script ist by utilizing the Awake() function.

Yes this is correct , only with not all variables does it work. But the thing is , even though some default references are accessible and able to be assigned to , im unclear how you use them , as @ runtime , they come back null. Or , you cant use these … than i ask , why are they there?

Good question, I dont know either. I will have a look into this at evening.