- Home /
Looking for a way to avoid using Update() Function
Hi!
I've been programming with unity for some time, but now im starting a project with friends and I started to look into ways of optimizing my scripts. I'm currently working on a 2D puzzle system that uses activators, outputlocks (once the output is high once, it remains high), logic doors and some receiver objects such as doors, platforms, etc.
I want to avoid the Update function, since most of this doesn't have to be verified every frame. Is there a way to use event systems or handlers to trigger a function when another script's boolean value changes?
For example: The player presses a button, the button's script changes it's 'output' value to true and another script detects that and calls a function once. Thanks!
I'd look into a Callback system. Basically you would add a connection to a variable with a function/event that will change it based on the input. I believe Unity might have one of these already in its library but I could be wrong. I'd show you an example but I gotta drive right now.
Sounds like a good place to start looking, thanks!
Some good stuff about events in the Unity tutorials: https://unity3d.com/learn/tutorials/topics/scripting/events?playlist=17117
Your answer
![](https://koobas.hobune.stream/wayback/20220612092750im_/https://answers.unity.com/themes/thub/images/avi.jpg)