Minimize RAM

Will this code reduce the amount of RAM being used?

void Update()
    {
        if ((renderer.enabled == false) && (Time.time > timeToWait))
        {
            renderer.enabled = true;
            rigidbody.useGravity = true;
  
        }
    }

That way, the program isn’t executing enabled and useGravity every frame.

1 Like

Yes! That is certainly better! Glad to see you are already thinking about those sort of things!

Don’t worry too much about those sort of things if you are not fully experienced, it won’t make much of a difference with a game this size and you’ll learn later better ways to optimize later in the course.

Thanks. I actually have my Technical Certification in Software Development and took a C# class. I usually select the 1.5 speed when he’s explaining C# like if statements and variables. I have some knowledge of Unity, but not much. Watching these tutorials are helping a lot!

Is there a better solution compared to mine? Is there a way to delete the script after the dropper is dropped?

As a rule of thumb, you want to use as few update methods as possible, in this case there are several solutions to achieve this:

  • You can use coroutines instead so the script stops running when it finishes.
  • You can destroy the script but that operation is quite taxing, if you destroy multiple scripts at the same time might not be a good idea.
  • You could use a single script that handles all the objects so there’s only one update instead of one per object.

I suppose there are more. Just keep in mind that there’s usually no need for these types of micro-optimizations unless your game is super heavy, like AAA type of game.

Thank you for this information.

1 Like

Thats where i disagree =D

first 200 loops.
secont 200 updates.
Well you cant surely say which is faster as i dont see any difference


1 Like

There are many ways in which you could approach an object handler like the one I described, one way could be using a loop during Update but, as you pointed out, that kinda kills the purpose.

Another way in which someone could approach this is to use a single coroutine in a single script, create a dictionary with timers and positions/objects to activate the objects when the timer reaches a certain point, then re-start the coroutine if required. This might look like a hassle and it is, that’s why people often don’t optimize at this level.

1 Like

ye thats ruins game maintainability and would be a big pain.

Thanks everyone for your feedback. I will keep this all in mind.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms