functions that aren´t called, are they using memory?.

Regarding to this:

  1. Don’t call a function if you don’t have to

The simplest and best of all optimizations is to perform less work. For example , when an enemy is far away it is most of the time perfectly acceptable to have the enemy fall asleep. That is do nothing until the player comes close. The slow way of handling this situation would be…

Allright, the message is understable, what happen if I have many functions in my script but they are not being called, do they use memory too? or just disk space (script kb)

Generally, yes, but is shared when possible.

ahh… allright, i have 20 functions that are not being called many times but i can´t delete them because they will be used at least 1 time in some moment… :\

I guess this musn´t waste too much memory… i hope… !

Memory can also be defined as space. If the functions are not being called they are not taking up ram. they are not performing anything. So any memory that they take up is virtually nill. The only concern, tho it is not significant by any means is the physical size of the memory. How big is your script? is your one script 100000 MB’s? Doubt it. Probably more like 70KB. So I doubt you have to be too concerned.

That is not too say memory and efficiency should not be at the forefront of any programming. Just being realistic.

I think you are over-analyzing how many methods/functions you’re using. Plenty of games have hundreds upon hundreds of functions without a performance hit. Try not attaching functions to objects - rather make classes for your methods and call methods from within the class when you need them.

class YourFunctions
{

void DoWhatYouWant()
{
//code goes here
}

}

object - > on entering some collider - > YourFunctions.DoWhatYouWant();

Static classes exist at compile time. Non-static are created when you create an instance of a particular method (object) so they won’t use memory until they are created - and the memory they use isn’t really much to get excited about.

99/100 times it won’t be code that slows your game down (unless you really botch a loop). Playtest your Unity game and take a look at the performance monitor - broken down into percentages of where your processor cyles are being donated per frame - most of the time any actual code only makes up 2-5% of what is happening each frame while graphics and physics take up the most beef.

Memory really isn’t an issue with scripting - graphics/physics are the no.1 culprit of slowmanship

if there is no ram usage with those functions, then there is no need to worry more, my script are not bigger than 100kb, so assuming to what you said, i will be fine… :slight_smile:

jsipich, well… i´m a fanatic of the optimizations, i guess i´m ill… :slight_smile:

thanks!

There’s nothing wrong with optimizing the heck out of code - makes the code far easier to read and edit :wink:

That is another good point…

yah,
just even stylizing the code, for lack of a better term help you digest it when you go back to read it later.
that means, all indents lined up, nice ////descriptions. Good use up space/returns.